Index: webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
diff --git a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
index 3337ccac38e4f5fd5e92c2ebf704d9fada009188..b121ba1d5addcf8feca7af1889e061a4d29ecea1 100644 |
--- a/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
+++ b/webkit/fileapi/obfuscated_file_system_file_util_unittest.cc |
@@ -66,6 +66,33 @@ const CopyMoveTestCaseRecord kCopyMoveTestCases[] = { |
{false, "dir0/file0", "dir1/file1", true}, |
}; |
+struct MigrationTestCaseRecord { |
+ bool is_directory; |
+ const FilePath::CharType path[64]; |
+ int64 data_file_size; |
+}; |
+ |
+const MigrationTestCaseRecord kMigrationTestCases[] = { |
+ {true, "dir a", 0}, |
+ {true, "dir a/dir a", 0}, |
+ {true, "dir a/dir d", 0}, |
+ {true, "dir a/dir d/dir e", 0}, |
+ {true, "dir a/dir d/dir e/dir f", 0}, |
+ {true, "dir a/dir d/dir e/dir g", 0}, |
+ {true, "dir a/dir d/dir e/dir h", 0}, |
+ {true, "dir b", 0}, |
+ {true, "dir b/dir a", 0}, |
+ {true, "dir c", 0}, |
+ {false, "file 0", 38}, |
+ {false, "file 2", 60}, |
+ {false, "file 3", 0}, |
+ {false, "dir a/file 0", 39}, |
+ {false, "dir a/dir d/dir e/dir g/file 0", 40}, |
+ {false, "dir a/dir d/dir e/dir g/file 1", 41}, |
+ {false, "dir a/dir d/dir e/dir g/file 2", 42}, |
+ {false, "dir a/dir d/dir e/dir g/file 3", 50}, |
+}; |
+ |
} // namespace (anonymous) |
// TODO(ericu): The vast majority of this and the other FSFU subclass tests |
@@ -100,6 +127,10 @@ class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
return obfuscated_file_system_file_util_.get(); |
} |
+ const FilePath& test_directory() const { |
+ return data_dir_.path(); |
+ } |
+ |
int64 GetSize(const FilePath& path) { |
int64 size; |
EXPECT_TRUE(file_util::GetFileSize(path, &size)); |
@@ -753,3 +784,69 @@ TEST_F(ObfuscatedFileSystemFileUtilTest, TestEnumerator) { |
context.reset(NewContext()); |
EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
} |
+ |
+TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
+ ScopedTempDir source_dir; |
+ ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
+ FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
+ ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
+ |
+ for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
+ SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); |
+ const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
+ FilePath local_src_path = root_path.Append(test_case.path); |
+ if (test_case.is_directory) { |
+ ASSERT_TRUE( |
+ file_util::CreateDirectory(local_src_path)); |
+ } else { |
+ base::PlatformFileError error_code; |
+ bool created = false; |
+ int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
+ base::PlatformFile file_handle = |
+ base::CreatePlatformFile( |
+ local_src_path, file_flags, &created, &error_code); |
+ EXPECT_TRUE(created); |
+ ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
+ ASSERT_TRUE( |
+ base::TruncatePlatformFile(file_handle, test_case.data_file_size)); |
+ EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
+ } |
+ } |
+ |
+ const GURL origin_url("http://example.com"); |
+ FileSystemType type = kFileSystemTypeTemporary; |
+ EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin_url, type, root_path)); |
+ |
+ FilePath new_root = |
+ test_directory().AppendASCII("000").Append( |
+ ofsfu()->GetDirectoryNameForType(type)).AppendASCII("Legacy"); |
+ for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
+ SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); |
+ const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
+ FilePath local_data_path = new_root.Append(test_case.path); |
+ scoped_ptr<FileSystemOperationContext> context(NewContext()); |
+ base::PlatformFileInfo ofsfu_file_info; |
+ FilePath data_path; |
+ SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
+ EXPECT_EQ(base::PLATFORM_FILE_OK, |
+ ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), |
+ &ofsfu_file_info, &data_path)); |
+ if (test_case.is_directory) { |
+ EXPECT_TRUE(ofsfu_file_info.is_directory); |
+ } else { |
+ base::PlatformFileInfo platform_file_info; |
+ SCOPED_TRACE(testing::Message() << "local_data_path is " << |
+ local_data_path.value()); |
+ ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
+ EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
+ EXPECT_FALSE(platform_file_info.is_directory); |
+ scoped_ptr<FileSystemOperationContext> context(NewContext()); |
+ EXPECT_EQ(local_data_path, data_path); |
+ EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); |
+ EXPECT_FALSE(ofsfu_file_info.is_directory); |
+ } |
+ } |
+} |
+ |
+//bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( |
+// const GURL& origin_url, FileSystemType type, const FilePath& src_root) { |