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 "extensions/browser/value_store/value_store_unittest.h" | 5 #include "extensions/browser/value_store/value_store_unittest.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ->HasError()); | 159 ->HasError()); |
160 } | 160 } |
161 | 161 |
162 // Close it (so we remove the lock), and replace all files with LolCats. | 162 // Close it (so we remove the lock), and replace all files with LolCats. |
163 CloseStore(); | 163 CloseStore(); |
164 base::FileEnumerator enumerator( | 164 base::FileEnumerator enumerator( |
165 database_path(), true /* recursive */, base::FileEnumerator::FILES); | 165 database_path(), true /* recursive */, base::FileEnumerator::FILES); |
166 for (base::FilePath file = enumerator.Next(); !file.empty(); | 166 for (base::FilePath file = enumerator.Next(); !file.empty(); |
167 file = enumerator.Next()) { | 167 file = enumerator.Next()) { |
168 // WriteFile() failure is a result of -1. | 168 // WriteFile() failure is a result of -1. |
169 ASSERT_NE(file_util::WriteFile(file, kLolCats.c_str(), kLolCats.length()), | 169 ASSERT_NE(base::WriteFile(file, kLolCats.c_str(), kLolCats.length()), |
170 -1); | 170 -1); |
171 } | 171 } |
172 OpenStore(); | 172 OpenStore(); |
173 | 173 |
174 // We should definitely have an error. | 174 // We should definitely have an error. |
175 ValueStore::ReadResult result = store()->Get(); | 175 ValueStore::ReadResult result = store()->Get(); |
176 ASSERT_TRUE(result->HasError()); | 176 ASSERT_TRUE(result->HasError()); |
177 ASSERT_EQ(ValueStore::CORRUPTION, result->error().code); | 177 ASSERT_EQ(ValueStore::CORRUPTION, result->error().code); |
178 | 178 |
179 ASSERT_TRUE(store()->Restore()); | 179 ASSERT_TRUE(store()->Restore()); |
180 result = store()->Get(); | 180 result = store()->Get(); |
181 EXPECT_FALSE(result->HasError()); | 181 EXPECT_FALSE(result->HasError()); |
182 // We couldn't recover anything, but we should be in a sane state again. | 182 // We couldn't recover anything, but we should be in a sane state again. |
183 EXPECT_EQ(0u, result->settings().size()); | 183 EXPECT_EQ(0u, result->settings().size()); |
184 } | 184 } |
OLD | NEW |