OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/prefs/json_pref_store.h" | 5 #include "base/prefs/json_pref_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); | 921 WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
922 ASSERT_TRUE(file_writer->HasPendingWrite()); | 922 ASSERT_TRUE(file_writer->HasPendingWrite()); |
923 | 923 |
924 // Call DoScheduledWrite and check both prefs get written. | 924 // Call DoScheduledWrite and check both prefs get written. |
925 file_writer->DoScheduledWrite(); | 925 file_writer->DoScheduledWrite(); |
926 ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}", | 926 ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}", |
927 GetTestFileContents()); | 927 GetTestFileContents()); |
928 ASSERT_FALSE(file_writer->HasPendingWrite()); | 928 ASSERT_FALSE(file_writer->HasPendingWrite()); |
929 } | 929 } |
930 | 930 |
| 931 TEST_F(JsonPrefStoreLossyWriteTest, ScheduleLossyWrite) { |
| 932 scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
| 933 ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store); |
| 934 |
| 935 // Set a lossy pref and check that it is not scheduled to be written. |
| 936 pref_store->SetValue("lossy", new base::StringValue("lossy"), |
| 937 WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 938 ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 939 |
| 940 // Schedule pending lossy writes and check that it is scheduled. |
| 941 pref_store->SchedulePendingLossyWrites(); |
| 942 ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 943 |
| 944 // Call CommitPendingWrite and check that the lossy pref is there with the |
| 945 // last value set above. |
| 946 pref_store->CommitPendingWrite(); |
| 947 ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 948 ASSERT_EQ("{\"lossy\":\"lossy\"}", GetTestFileContents()); |
| 949 } |
| 950 |
931 } // namespace base | 951 } // namespace base |
OLD | NEW |