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

Side by Side Diff: webkit/fileapi/file_system_origin_database_unittest.cc

Issue 13946004: FileAPI: Run database recovery on IOError. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment, +test for other db files Created 7 years, 8 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 unified diff | Download patch
« no previous file with comments | « webkit/fileapi/file_system_origin_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <functional> 6 #include <functional>
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const std::string kOrigin("piyo.example.org"); 251 const std::string kOrigin("piyo.example.org");
252 EXPECT_FALSE(database->HasOriginPath(kOrigin)); 252 EXPECT_FALSE(database->HasOriginPath(kOrigin));
253 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path)); 253 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
254 EXPECT_FALSE(path.empty()); 254 EXPECT_FALSE(path.empty());
255 EXPECT_TRUE(database->HasOriginPath(kOrigin)); 255 EXPECT_TRUE(database->HasOriginPath(kOrigin));
256 256
257 EXPECT_FALSE(file_util::PathExists(kGarbageFile)); 257 EXPECT_FALSE(file_util::PathExists(kGarbageFile));
258 EXPECT_FALSE(file_util::PathExists(kGarbageDir)); 258 EXPECT_FALSE(file_util::PathExists(kGarbageDir));
259 } 259 }
260 260
261 TEST(FileSystemOriginDatabaseTest, DatabaseRecoveryForMissingDBFileTest) {
262 const leveldb::FileType kLevelDBFileTypes[] = {
263 leveldb::kLogFile,
264 leveldb::kDBLockFile,
265 leveldb::kTableFile,
266 leveldb::kDescriptorFile,
267 leveldb::kCurrentFile,
268 leveldb::kTempFile,
269 leveldb::kInfoLogFile,
270 };
271
272 for (size_t i = 0; i < arraysize(kLevelDBFileTypes); ++i) {
273 base::ScopedTempDir dir;
274 ASSERT_TRUE(dir.CreateUniqueTempDir());
275 const base::FilePath kFSDir = dir.path().Append(kFileSystemDirName);
276 const base::FilePath kDBDir = kFSDir.Append(kOriginDatabaseName);
277 EXPECT_FALSE(file_util::PathExists(kFSDir));
278 EXPECT_TRUE(file_util::CreateDirectory(kFSDir));
279
280 const std::string kOrigin = "foo.example.com";
281 base::FilePath path;
282
283 scoped_ptr<FileSystemOriginDatabase> database(
284 new FileSystemOriginDatabase(kFSDir));
285 EXPECT_FALSE(database->HasOriginPath(kOrigin));
286 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
287 EXPECT_FALSE(path.empty());
288 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
289 EXPECT_TRUE(file_util::CreateDirectory(kFSDir.Append(path)));
290 database.reset();
291
292 DeleteDatabaseFile(kDBDir, kLevelDBFileTypes[i]);
293
294 database.reset(new FileSystemOriginDatabase(kFSDir));
295 std::vector<FileSystemOriginDatabase::OriginRecord> origins_in_db;
296 EXPECT_TRUE(database->ListAllOrigins(&origins_in_db));
297
298 const std::string kOrigin2("piyo.example.org");
299 EXPECT_FALSE(database->HasOriginPath(kOrigin2));
300 EXPECT_TRUE(database->GetPathForOrigin(kOrigin2, &path));
301 EXPECT_FALSE(path.empty());
302 EXPECT_TRUE(database->HasOriginPath(kOrigin2));
303 }
304 }
305
261 } // namespace fileapi 306 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_origin_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698