OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" | 9 #include "webkit/browser/fileapi/sandbox_isolated_origin_database.h" |
10 #include "webkit/browser/fileapi/sandbox_origin_database.h" | 10 #include "webkit/browser/fileapi/sandbox_origin_database.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 std::string kOrigin("origin"); | 40 std::string kOrigin("origin"); |
41 std::string kFakeDirectoryData("0123456789"); | 41 std::string kFakeDirectoryData("0123456789"); |
42 base::FilePath path; | 42 base::FilePath path; |
43 base::FilePath old_db_path; | 43 base::FilePath old_db_path; |
44 | 44 |
45 // Initialize the directory with one origin using the regular | 45 // Initialize the directory with one origin using the regular |
46 // SandboxOriginDatabase. | 46 // SandboxOriginDatabase. |
47 { | 47 { |
48 SandboxOriginDatabase database_old(dir.path()); | 48 SandboxOriginDatabase database_old(dir.path()); |
49 old_db_path = database_old.GetDatabasePath(); | 49 old_db_path = database_old.GetDatabasePath(); |
50 EXPECT_FALSE(file_util::PathExists(old_db_path)); | 50 EXPECT_FALSE(base::PathExists(old_db_path)); |
51 EXPECT_TRUE(database_old.GetPathForOrigin(kOrigin, &path)); | 51 EXPECT_TRUE(database_old.GetPathForOrigin(kOrigin, &path)); |
52 EXPECT_FALSE(path.empty()); | 52 EXPECT_FALSE(path.empty()); |
53 EXPECT_TRUE(file_util::DirectoryExists(old_db_path)); | 53 EXPECT_TRUE(file_util::DirectoryExists(old_db_path)); |
54 | 54 |
55 // Populate the origin directory with some fake data. | 55 // Populate the origin directory with some fake data. |
56 base::FilePath directory_db_path = dir.path().Append(path); | 56 base::FilePath directory_db_path = dir.path().Append(path); |
57 ASSERT_TRUE(file_util::CreateDirectory(directory_db_path)); | 57 ASSERT_TRUE(file_util::CreateDirectory(directory_db_path)); |
58 EXPECT_EQ(static_cast<int>(kFakeDirectoryData.size()), | 58 EXPECT_EQ(static_cast<int>(kFakeDirectoryData.size()), |
59 file_util::WriteFile(directory_db_path.AppendASCII("dummy"), | 59 file_util::WriteFile(directory_db_path.AppendASCII("dummy"), |
60 kFakeDirectoryData.data(), | 60 kFakeDirectoryData.data(), |
61 kFakeDirectoryData.size())); | 61 kFakeDirectoryData.size())); |
62 } | 62 } |
63 | 63 |
64 // Re-open the directory using sandboxIsolatedOriginDatabase. | 64 // Re-open the directory using sandboxIsolatedOriginDatabase. |
65 SandboxIsolatedOriginDatabase database(kOrigin, dir.path()); | 65 SandboxIsolatedOriginDatabase database(kOrigin, dir.path()); |
66 | 66 |
67 // The database is migrated from the old one, so we should still | 67 // The database is migrated from the old one, so we should still |
68 // see the same origin. | 68 // see the same origin. |
69 EXPECT_TRUE(database.HasOriginPath(kOrigin)); | 69 EXPECT_TRUE(database.HasOriginPath(kOrigin)); |
70 EXPECT_TRUE(database.GetPathForOrigin(kOrigin, &path)); | 70 EXPECT_TRUE(database.GetPathForOrigin(kOrigin, &path)); |
71 EXPECT_FALSE(path.empty()); | 71 EXPECT_FALSE(path.empty()); |
72 | 72 |
73 // The directory content must be kept (or migrated if necessary), | 73 // The directory content must be kept (or migrated if necessary), |
74 // so we should see the same fake data. | 74 // so we should see the same fake data. |
75 std::string origin_db_data; | 75 std::string origin_db_data; |
76 base::FilePath directory_db_path = dir.path().Append(path); | 76 base::FilePath directory_db_path = dir.path().Append(path); |
77 EXPECT_TRUE(file_util::DirectoryExists(directory_db_path)); | 77 EXPECT_TRUE(file_util::DirectoryExists(directory_db_path)); |
78 EXPECT_TRUE(file_util::PathExists(directory_db_path.AppendASCII("dummy"))); | 78 EXPECT_TRUE(base::PathExists(directory_db_path.AppendASCII("dummy"))); |
79 EXPECT_TRUE(file_util::ReadFileToString( | 79 EXPECT_TRUE(file_util::ReadFileToString( |
80 directory_db_path.AppendASCII("dummy"), &origin_db_data)); | 80 directory_db_path.AppendASCII("dummy"), &origin_db_data)); |
81 EXPECT_EQ(kFakeDirectoryData, origin_db_data); | 81 EXPECT_EQ(kFakeDirectoryData, origin_db_data); |
82 | 82 |
83 // After the migration the database must be gone. | 83 // After the migration the database must be gone. |
84 EXPECT_FALSE(file_util::PathExists(old_db_path)); | 84 EXPECT_FALSE(base::PathExists(old_db_path)); |
85 } | 85 } |
86 | 86 |
87 } // namespace fileapi | 87 } // namespace fileapi |
OLD | NEW |