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

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: simplify test helper 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
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, DatabaseRecoveryForMissingManifestTest) {
262 base::ScopedTempDir dir;
263 ASSERT_TRUE(dir.CreateUniqueTempDir());
264 const base::FilePath kFSDir = dir.path().Append(kFileSystemDirName);
265 const base::FilePath kDBDir = kFSDir.Append(kOriginDatabaseName);
266 EXPECT_FALSE(file_util::PathExists(kFSDir));
267 EXPECT_TRUE(file_util::CreateDirectory(kFSDir));
268
269 const std::string kOrigin = "foo.example.com";
270 base::FilePath path;
271
272 scoped_ptr<FileSystemOriginDatabase> database(
273 new FileSystemOriginDatabase(kFSDir));
274 EXPECT_FALSE(database->HasOriginPath(kOrigin));
275 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
276 EXPECT_FALSE(path.empty());
277 EXPECT_TRUE(database->GetPathForOrigin(kOrigin, &path));
278 EXPECT_TRUE(file_util::CreateDirectory(kFSDir.Append(path)));
279 database.reset();
280
281 DeleteDatabaseFile(kDBDir, leveldb::kDescriptorFile);
282
283 database.reset(new FileSystemOriginDatabase(kFSDir));
284 std::vector<FileSystemOriginDatabase::OriginRecord> origins_in_db;
285 EXPECT_TRUE(database->ListAllOrigins(&origins_in_db));
286
287 EXPECT_EQ(1u, origins_in_db.size());
288
289 const std::string kOrigin2("piyo.example.org");
290 EXPECT_FALSE(database->HasOriginPath(kOrigin2));
291 EXPECT_TRUE(database->GetPathForOrigin(kOrigin2, &path));
292 EXPECT_FALSE(path.empty());
293 EXPECT_TRUE(database->HasOriginPath(kOrigin2));
294 }
295
261 } // namespace fileapi 296 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698