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

Unified Diff: components/prefs/json_pref_store_unittest.cc

Issue 2751603002: Remove the alternative preferences filename from JsonPrefStore. (Closed)
Patch Set: Created 3 years, 9 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 | « components/prefs/json_pref_store.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/prefs/json_pref_store_unittest.cc
diff --git a/components/prefs/json_pref_store_unittest.cc b/components/prefs/json_pref_store_unittest.cc
index 0164ad65880df13c5f5386334213ead478ee043c..cae79d3414397284cc5568f71a62aaa2a5a21562 100644
--- a/components/prefs/json_pref_store_unittest.cc
+++ b/components/prefs/json_pref_store_unittest.cc
@@ -166,21 +166,6 @@ TEST_F(JsonPrefStoreTest, NonExistentFile) {
EXPECT_FALSE(pref_store->ReadOnly());
}
-// Test fallback behavior for a nonexistent file and alternate file.
-TEST_F(JsonPrefStoreTest, NonExistentFileAndAlternateFile) {
- base::FilePath bogus_input_file = temp_dir_.GetPath().AppendASCII("read.txt");
- base::FilePath bogus_alternate_input_file =
- temp_dir_.GetPath().AppendASCII("read_alternate.txt");
- ASSERT_FALSE(PathExists(bogus_input_file));
- ASSERT_FALSE(PathExists(bogus_alternate_input_file));
- scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
- bogus_input_file, bogus_alternate_input_file, message_loop_.task_runner(),
- std::unique_ptr<PrefFilter>());
- EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE,
- pref_store->ReadPrefs());
- EXPECT_FALSE(pref_store->ReadOnly());
-}
-
// Test fallback behavior for an invalid file.
TEST_F(JsonPrefStoreTest, InvalidFile) {
base::FilePath invalid_file = temp_dir_.GetPath().AppendASCII("invalid.json");
@@ -518,171 +503,6 @@ TEST_F(JsonPrefStoreTest, ReadAsyncWithInterceptor) {
RunBasicJsonPrefStoreTest(pref_store.get(), input_file);
}
-TEST_F(JsonPrefStoreTest, AlternateFile) {
- base::FilePath alternate_input_file =
- temp_dir_.GetPath().AppendASCII("alternate.json");
- ASSERT_LT(0, base::WriteFile(alternate_input_file,
- kReadJson, arraysize(kReadJson) - 1));
-
- // Test that the alternate file is moved to the main file and read as-is from
- // there.
- base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json");
- ASSERT_FALSE(PathExists(input_file));
- ASSERT_TRUE(PathExists(alternate_input_file));
- scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
- input_file, alternate_input_file, message_loop_.task_runner(),
- std::unique_ptr<PrefFilter>());
-
- ASSERT_FALSE(PathExists(input_file));
- ASSERT_TRUE(PathExists(alternate_input_file));
- ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_FALSE(PathExists(alternate_input_file));
-
- EXPECT_FALSE(pref_store->ReadOnly());
- EXPECT_TRUE(pref_store->IsInitializationComplete());
-
- // The JSON file looks like this:
- // {
- // "homepage": "http://www.cnn.com",
- // "some_directory": "/usr/local/",
- // "tabs": {
- // "new_windows_in_tabs": true,
- // "max_tabs": 20
- // }
- // }
-
- RunBasicJsonPrefStoreTest(pref_store.get(), input_file);
-}
-
-TEST_F(JsonPrefStoreTest, AlternateFileIgnoredWhenMainFileExists) {
- base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json");
- ASSERT_LT(0, base::WriteFile(input_file,
- kReadJson, arraysize(kReadJson) - 1));
-
- base::FilePath alternate_input_file =
- temp_dir_.GetPath().AppendASCII("alternate.json");
- ASSERT_LT(0, base::WriteFile(alternate_input_file,
- kInvalidJson, arraysize(kInvalidJson) - 1));
-
- // Test that the alternate file is ignored and that the read occurs from the
- // existing main file. There is no attempt at even deleting the alternate
- // file as this scenario should never happen in normal user-data-dirs.
- scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
- input_file, alternate_input_file, message_loop_.task_runner(),
- std::unique_ptr<PrefFilter>());
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_TRUE(PathExists(alternate_input_file));
- ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_TRUE(PathExists(alternate_input_file));
-
- EXPECT_FALSE(pref_store->ReadOnly());
- EXPECT_TRUE(pref_store->IsInitializationComplete());
-
- // The JSON file looks like this:
- // {
- // "homepage": "http://www.cnn.com",
- // "some_directory": "/usr/local/",
- // "tabs": {
- // "new_windows_in_tabs": true,
- // "max_tabs": 20
- // }
- // }
-
- RunBasicJsonPrefStoreTest(pref_store.get(), input_file);
-}
-
-TEST_F(JsonPrefStoreTest, AlternateFileDNE) {
- base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json");
- ASSERT_LT(0, base::WriteFile(input_file,
- kReadJson, arraysize(kReadJson) - 1));
-
- // Test that the basic read works fine when an alternate file is specified but
- // does not exist.
- base::FilePath alternate_input_file =
- temp_dir_.GetPath().AppendASCII("alternate.json");
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_FALSE(PathExists(alternate_input_file));
- scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
- input_file, alternate_input_file, message_loop_.task_runner(),
- std::unique_ptr<PrefFilter>());
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_FALSE(PathExists(alternate_input_file));
- ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_FALSE(PathExists(alternate_input_file));
-
- EXPECT_FALSE(pref_store->ReadOnly());
- EXPECT_TRUE(pref_store->IsInitializationComplete());
-
- // The JSON file looks like this:
- // {
- // "homepage": "http://www.cnn.com",
- // "some_directory": "/usr/local/",
- // "tabs": {
- // "new_windows_in_tabs": true,
- // "max_tabs": 20
- // }
- // }
-
- RunBasicJsonPrefStoreTest(pref_store.get(), input_file);
-}
-
-TEST_F(JsonPrefStoreTest, BasicAsyncWithAlternateFile) {
- base::FilePath alternate_input_file =
- temp_dir_.GetPath().AppendASCII("alternate.json");
- ASSERT_LT(0, base::WriteFile(alternate_input_file,
- kReadJson, arraysize(kReadJson) - 1));
-
- // Test that the alternate file is moved to the main file and read as-is from
- // there even when the read is made asynchronously.
- base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json");
- scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
- input_file, alternate_input_file, message_loop_.task_runner(),
- std::unique_ptr<PrefFilter>());
-
- ASSERT_FALSE(PathExists(input_file));
- ASSERT_TRUE(PathExists(alternate_input_file));
-
- {
- MockPrefStoreObserver mock_observer;
- pref_store->AddObserver(&mock_observer);
-
- MockReadErrorDelegate* mock_error_delegate = new MockReadErrorDelegate;
- pref_store->ReadPrefsAsync(mock_error_delegate);
-
- EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1);
- EXPECT_CALL(*mock_error_delegate,
- OnError(PersistentPrefStore::PREF_READ_ERROR_NONE)).Times(0);
- RunLoop().RunUntilIdle();
- pref_store->RemoveObserver(&mock_observer);
-
- EXPECT_FALSE(pref_store->ReadOnly());
- EXPECT_TRUE(pref_store->IsInitializationComplete());
- }
-
- ASSERT_TRUE(PathExists(input_file));
- ASSERT_FALSE(PathExists(alternate_input_file));
-
- // The JSON file looks like this:
- // {
- // "homepage": "http://www.cnn.com",
- // "some_directory": "/usr/local/",
- // "tabs": {
- // "new_windows_in_tabs": true,
- // "max_tabs": 20
- // }
- // }
-
- RunBasicJsonPrefStoreTest(pref_store.get(), input_file);
-}
-
TEST_F(JsonPrefStoreTest, WriteCountHistogramTestBasic) {
base::HistogramTester histogram_tester;
« no previous file with comments | « components/prefs/json_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698