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

Unified Diff: base/prefs/json_pref_store_unittest.cc

Issue 1136983004: Revert of Implement lossy pref behavior for JsonPrefStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs-fix-flags
Patch Set: Created 5 years, 7 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 | « base/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: base/prefs/json_pref_store_unittest.cc
diff --git a/base/prefs/json_pref_store_unittest.cc b/base/prefs/json_pref_store_unittest.cc
index 67a8adbb4d4f93bca61d964ace97353736345f3f..0fab8685e9b21410731955169bad35b5d98ceef2 100644
--- a/base/prefs/json_pref_store_unittest.cc
+++ b/base/prefs/json_pref_store_unittest.cc
@@ -108,7 +108,9 @@
void TearDown() override {
// Make sure all pending tasks have been processed (e.g., deleting the
// JsonPrefStore may post write tasks).
- RunLoop().RunUntilIdle();
+ message_loop_.task_runner()->PostTask(FROM_HERE,
+ MessageLoop::QuitWhenIdleClosure());
+ message_loop_.Run();
}
// The path to temporary directory used to contain the test operations.
@@ -125,7 +127,7 @@
// Test fallback behavior for a nonexistent file.
TEST_F(JsonPrefStoreTest, NonExistentFile) {
- base::FilePath bogus_input_file = temp_dir_.path().AppendASCII("read.txt");
+ base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(PathExists(bogus_input_file));
scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
bogus_input_file, message_loop_.task_runner(), scoped_ptr<PrefFilter>());
@@ -136,9 +138,9 @@
// Test fallback behavior for a nonexistent file and alternate file.
TEST_F(JsonPrefStoreTest, NonExistentFileAndAlternateFile) {
- base::FilePath bogus_input_file = temp_dir_.path().AppendASCII("read.txt");
+ base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
base::FilePath bogus_alternate_input_file =
- temp_dir_.path().AppendASCII("read_alternate.txt");
+ data_dir_.AppendASCII("read_alternate.txt");
ASSERT_FALSE(PathExists(bogus_input_file));
ASSERT_FALSE(PathExists(bogus_alternate_input_file));
scoped_refptr<JsonPrefStore> pref_store =
@@ -319,7 +321,7 @@
// Write to file.
pref_store->CommitPendingWrite();
- RunLoop().RunUntilIdle();
+ MessageLoop::current()->RunUntilIdle();
// Reload.
pref_store = new JsonPrefStore(pref_file, message_loop_.task_runner(),
@@ -358,7 +360,7 @@
// Tests asynchronous reading of the file when there is no file.
TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
- base::FilePath bogus_input_file = temp_dir_.path().AppendASCII("read.txt");
+ base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(PathExists(bogus_input_file));
scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
bogus_input_file, message_loop_.task_runner(), scoped_ptr<PrefFilter>());
@@ -807,125 +809,4 @@
ASSERT_EQ(6, samples->TotalCount());
}
-class JsonPrefStoreLossyWriteTest : public JsonPrefStoreTest {
- protected:
- void SetUp() override {
- JsonPrefStoreTest::SetUp();
- test_file_ = temp_dir_.path().AppendASCII("test.json");
- }
-
- // Creates a JsonPrefStore with the given |file_writer|.
- scoped_refptr<JsonPrefStore> CreatePrefStore() {
- return new JsonPrefStore(test_file_, message_loop_.task_runner(),
- scoped_ptr<PrefFilter>());
- }
-
- // Return the ImportantFileWriter for a given JsonPrefStore.
- ImportantFileWriter* GetImportantFileWriter(
- scoped_refptr<JsonPrefStore> pref_store) {
- return &(pref_store->writer_);
- }
-
- // Get the contents of kTestFile. Pumps the message loop before returning the
- // result.
- std::string GetTestFileContents() {
- RunLoop().RunUntilIdle();
- std::string file_contents;
- ReadFileToString(test_file_, &file_contents);
- return file_contents;
- }
-
- private:
- base::FilePath test_file_;
-};
-
-TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteBasic) {
- scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore();
- ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store);
-
- // Set a normal pref and check that it gets scheduled to be written.
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("normal", new base::StringValue("normal"),
- WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
- ASSERT_TRUE(file_writer->HasPendingWrite());
- file_writer->DoScheduledWrite();
- ASSERT_EQ("{\"normal\":\"normal\"}", GetTestFileContents());
- ASSERT_FALSE(file_writer->HasPendingWrite());
-
- // Set a lossy pref and check that it is not scheduled to be written.
- // SetValue/RemoveValue.
- pref_store->SetValue("lossy", new base::StringValue("lossy"),
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->RemoveValue("lossy", WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
-
- // SetValueSilently/RemoveValueSilently.
- pref_store->SetValueSilently("lossy", new base::StringValue("lossy"),
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->RemoveValueSilently("lossy",
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
-
- // ReportValueChanged.
- pref_store->SetValue("lossy", new base::StringValue("lossy"),
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->ReportValueChanged("lossy",
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
-
- // Call CommitPendingWrite and check that the lossy pref and the normal pref
- // are there with the last values set above.
- pref_store->CommitPendingWrite();
- ASSERT_FALSE(file_writer->HasPendingWrite());
- ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}",
- GetTestFileContents());
-}
-
-TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossyFirst) {
- scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore();
- ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store);
-
- // Set a lossy pref and check that it is not scheduled to be written.
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("lossy", new base::StringValue("lossy"),
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_FALSE(file_writer->HasPendingWrite());
-
- // Set a normal pref and check that it is scheduled to be written.
- pref_store->SetValue("normal", new base::StringValue("normal"),
- WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
- ASSERT_TRUE(file_writer->HasPendingWrite());
-
- // Call DoScheduledWrite and check both prefs get written.
- file_writer->DoScheduledWrite();
- ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}",
- GetTestFileContents());
- ASSERT_FALSE(file_writer->HasPendingWrite());
-}
-
-TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossySecond) {
- scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore();
- ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store);
-
- // Set a normal pref and check that it is scheduled to be written.
- ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("normal", new base::StringValue("normal"),
- WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
- ASSERT_TRUE(file_writer->HasPendingWrite());
-
- // Set a lossy pref and check that the write is still scheduled.
- pref_store->SetValue("lossy", new base::StringValue("lossy"),
- WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
- ASSERT_TRUE(file_writer->HasPendingWrite());
-
- // Call DoScheduledWrite and check both prefs get written.
- file_writer->DoScheduledWrite();
- ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}",
- GetTestFileContents());
- ASSERT_FALSE(file_writer->HasPendingWrite());
-}
-
} // namespace base
« no previous file with comments | « base/prefs/json_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698