| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <functional> | 6 #include <functional> |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/platform_file.h" | |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/leveldatabase/src/db/filename.h" | 17 #include "third_party/leveldatabase/src/db/filename.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 19 #include "webkit/browser/fileapi/sandbox_database_test_helper.h" | 19 #include "webkit/browser/fileapi/sandbox_database_test_helper.h" |
| 20 #include "webkit/browser/fileapi/sandbox_origin_database.h" | 20 #include "webkit/browser/fileapi/sandbox_origin_database.h" |
| 21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
| 22 | 22 |
| 23 namespace fileapi { | 23 namespace fileapi { |
| 24 | 24 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 EXPECT_TRUE(database->GetPathForOrigin(kOrigins[i], &path)); | 217 EXPECT_TRUE(database->GetPathForOrigin(kOrigins[i], &path)); |
| 218 | 218 |
| 219 if (i != 1) | 219 if (i != 1) |
| 220 EXPECT_TRUE(base::CreateDirectory(kFSDir.Append(path))); | 220 EXPECT_TRUE(base::CreateDirectory(kFSDir.Append(path))); |
| 221 } | 221 } |
| 222 database.reset(); | 222 database.reset(); |
| 223 | 223 |
| 224 const base::FilePath kGarbageDir = kFSDir.AppendASCII("foo"); | 224 const base::FilePath kGarbageDir = kFSDir.AppendASCII("foo"); |
| 225 const base::FilePath kGarbageFile = kGarbageDir.AppendASCII("bar"); | 225 const base::FilePath kGarbageFile = kGarbageDir.AppendASCII("bar"); |
| 226 EXPECT_TRUE(base::CreateDirectory(kGarbageDir)); | 226 EXPECT_TRUE(base::CreateDirectory(kGarbageDir)); |
| 227 bool created = false; | 227 base::File file(kGarbageFile, |
| 228 base::PlatformFileError error; | 228 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
| 229 base::PlatformFile file = base::CreatePlatformFile( | 229 EXPECT_TRUE(file.IsValid()); |
| 230 kGarbageFile, | 230 file.Close(); |
| 231 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | |
| 232 &created, &error); | |
| 233 EXPECT_EQ(base::PLATFORM_FILE_OK, error); | |
| 234 EXPECT_TRUE(created); | |
| 235 EXPECT_TRUE(base::ClosePlatformFile(file)); | |
| 236 | 231 |
| 237 // Corrupt database itself and last log entry to drop last 1 database | 232 // Corrupt database itself and last log entry to drop last 1 database |
| 238 // operation. The database should detect the corruption and should recover | 233 // operation. The database should detect the corruption and should recover |
| 239 // its consistency after recovery. | 234 // its consistency after recovery. |
| 240 CorruptDatabase(kDBDir, leveldb::kDescriptorFile, | 235 CorruptDatabase(kDBDir, leveldb::kDescriptorFile, |
| 241 0, std::numeric_limits<size_t>::max()); | 236 0, std::numeric_limits<size_t>::max()); |
| 242 CorruptDatabase(kDBDir, leveldb::kLogFile, -1, 1); | 237 CorruptDatabase(kDBDir, leveldb::kLogFile, -1, 1); |
| 243 | 238 |
| 244 base::FilePath path; | 239 base::FilePath path; |
| 245 database.reset(new SandboxOriginDatabase(kFSDir, NULL)); | 240 database.reset(new SandboxOriginDatabase(kFSDir, NULL)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 294 |
| 300 const std::string kOrigin2("piyo.example.org"); | 295 const std::string kOrigin2("piyo.example.org"); |
| 301 EXPECT_FALSE(database->HasOriginPath(kOrigin2)); | 296 EXPECT_FALSE(database->HasOriginPath(kOrigin2)); |
| 302 EXPECT_TRUE(database->GetPathForOrigin(kOrigin2, &path)); | 297 EXPECT_TRUE(database->GetPathForOrigin(kOrigin2, &path)); |
| 303 EXPECT_FALSE(path.empty()); | 298 EXPECT_FALSE(path.empty()); |
| 304 EXPECT_TRUE(database->HasOriginPath(kOrigin2)); | 299 EXPECT_TRUE(database->HasOriginPath(kOrigin2)); |
| 305 } | 300 } |
| 306 } | 301 } |
| 307 | 302 |
| 308 } // namespace fileapi | 303 } // namespace fileapi |
| OLD | NEW |