| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 {true, "dir0/file0", "dir1/file0", false}, | 59 {true, "dir0/file0", "dir1/file0", false}, |
| 60 {false, "dir0/file0", "dir1/file0", false}, | 60 {false, "dir0/file0", "dir1/file0", false}, |
| 61 {true, "dir0/file0", "dir1/file0", true}, | 61 {true, "dir0/file0", "dir1/file0", true}, |
| 62 {false, "dir0/file0", "dir1/file0", true}, | 62 {false, "dir0/file0", "dir1/file0", true}, |
| 63 {true, "dir0/file0", "dir1/file1", false}, | 63 {true, "dir0/file0", "dir1/file1", false}, |
| 64 {false, "dir0/file0", "dir1/file1", false}, | 64 {false, "dir0/file0", "dir1/file1", false}, |
| 65 {true, "dir0/file0", "dir1/file1", true}, | 65 {true, "dir0/file0", "dir1/file1", true}, |
| 66 {false, "dir0/file0", "dir1/file1", true}, | 66 {false, "dir0/file0", "dir1/file1", true}, |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 struct MigrationTestCaseRecord { |
| 70 bool is_directory; |
| 71 const FilePath::CharType path[64]; |
| 72 int64 data_file_size; |
| 73 }; |
| 74 |
| 75 const MigrationTestCaseRecord kMigrationTestCases[] = { |
| 76 {true, "dir a", 0}, |
| 77 {true, "dir a/dir a", 0}, |
| 78 {true, "dir a/dir d", 0}, |
| 79 {true, "dir a/dir d/dir e", 0}, |
| 80 {true, "dir a/dir d/dir e/dir f", 0}, |
| 81 {true, "dir a/dir d/dir e/dir g", 0}, |
| 82 {true, "dir a/dir d/dir e/dir h", 0}, |
| 83 {true, "dir b", 0}, |
| 84 {true, "dir b/dir a", 0}, |
| 85 {true, "dir c", 0}, |
| 86 {false, "file 0", 38}, |
| 87 {false, "file 2", 60}, |
| 88 {false, "file 3", 0}, |
| 89 {false, "dir a/file 0", 39}, |
| 90 {false, "dir a/dir d/dir e/dir g/file 0", 40}, |
| 91 {false, "dir a/dir d/dir e/dir g/file 1", 41}, |
| 92 {false, "dir a/dir d/dir e/dir g/file 2", 42}, |
| 93 {false, "dir a/dir d/dir e/dir g/file 3", 50}, |
| 94 }; |
| 95 |
| 69 } // namespace (anonymous) | 96 } // namespace (anonymous) |
| 70 | 97 |
| 71 // TODO(ericu): The vast majority of this and the other FSFU subclass tests | 98 // TODO(ericu): The vast majority of this and the other FSFU subclass tests |
| 72 // could theoretically be shared. It would basically be a FSFU interface | 99 // could theoretically be shared. It would basically be a FSFU interface |
| 73 // compliance test, and only the subclass-specific bits that look into the | 100 // compliance test, and only the subclass-specific bits that look into the |
| 74 // implementation would need to be written per-subclass. | 101 // implementation would need to be written per-subclass. |
| 75 class ObfuscatedFileSystemFileUtilTest : public testing::Test { | 102 class ObfuscatedFileSystemFileUtilTest : public testing::Test { |
| 76 public: | 103 public: |
| 77 ObfuscatedFileSystemFileUtilTest() { | 104 ObfuscatedFileSystemFileUtilTest() { |
| 78 } | 105 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 93 context->set_dest_type(kFileSystemTypeTemporary); | 120 context->set_dest_type(kFileSystemTypeTemporary); |
| 94 context->set_allowed_bytes_growth(1024 * 1024); | 121 context->set_allowed_bytes_growth(1024 * 1024); |
| 95 | 122 |
| 96 return context; | 123 return context; |
| 97 } | 124 } |
| 98 | 125 |
| 99 ObfuscatedFileSystemFileUtil* ofsfu() { | 126 ObfuscatedFileSystemFileUtil* ofsfu() { |
| 100 return obfuscated_file_system_file_util_.get(); | 127 return obfuscated_file_system_file_util_.get(); |
| 101 } | 128 } |
| 102 | 129 |
| 130 const FilePath& test_directory() const { |
| 131 return data_dir_.path(); |
| 132 } |
| 133 |
| 103 int64 GetSize(const FilePath& path) { | 134 int64 GetSize(const FilePath& path) { |
| 104 int64 size; | 135 int64 size; |
| 105 EXPECT_TRUE(file_util::GetFileSize(path, &size)); | 136 EXPECT_TRUE(file_util::GetFileSize(path, &size)); |
| 106 return size; | 137 return size; |
| 107 } | 138 } |
| 108 | 139 |
| 109 void CheckFileAndCloseHandle( | 140 void CheckFileAndCloseHandle( |
| 110 const FilePath& virtual_path, PlatformFile file_handle) { | 141 const FilePath& virtual_path, PlatformFile file_handle) { |
| 111 scoped_ptr<FileSystemOperationContext> context(NewContext()); | 142 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 112 FilePath local_path; | 143 FilePath local_path; |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); | 777 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), src_path)); |
| 747 context.reset(NewContext()); | 778 context.reset(NewContext()); |
| 748 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 779 EXPECT_TRUE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| 749 context.reset(NewContext()); | 780 context.reset(NewContext()); |
| 750 recursive = true; | 781 recursive = true; |
| 751 ASSERT_EQ(base::PLATFORM_FILE_OK, | 782 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 752 ofsfu()->Delete(context.get(), dest_path, recursive)); | 783 ofsfu()->Delete(context.get(), dest_path, recursive)); |
| 753 context.reset(NewContext()); | 784 context.reset(NewContext()); |
| 754 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); | 785 EXPECT_FALSE(ofsfu()->DirectoryExists(context.get(), dest_path)); |
| 755 } | 786 } |
| 787 |
| 788 TEST_F(ObfuscatedFileSystemFileUtilTest, TestMigration) { |
| 789 ScopedTempDir source_dir; |
| 790 ASSERT_TRUE(source_dir.CreateUniqueTempDir()); |
| 791 FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); |
| 792 ASSERT_TRUE(file_util::CreateDirectory(root_path)); |
| 793 |
| 794 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 795 SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); |
| 796 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 797 FilePath local_src_path = root_path.Append(test_case.path); |
| 798 if (test_case.is_directory) { |
| 799 ASSERT_TRUE( |
| 800 file_util::CreateDirectory(local_src_path)); |
| 801 } else { |
| 802 base::PlatformFileError error_code; |
| 803 bool created = false; |
| 804 int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; |
| 805 base::PlatformFile file_handle = |
| 806 base::CreatePlatformFile( |
| 807 local_src_path, file_flags, &created, &error_code); |
| 808 EXPECT_TRUE(created); |
| 809 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); |
| 810 ASSERT_TRUE( |
| 811 base::TruncatePlatformFile(file_handle, test_case.data_file_size)); |
| 812 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); |
| 813 } |
| 814 } |
| 815 |
| 816 const GURL origin_url("http://example.com"); |
| 817 FileSystemType type = kFileSystemTypeTemporary; |
| 818 EXPECT_TRUE(ofsfu()->MigrateFromOldSandbox(origin_url, type, root_path)); |
| 819 |
| 820 FilePath new_root = |
| 821 test_directory().AppendASCII("000").Append( |
| 822 ofsfu()->GetDirectoryNameForType(type)).AppendASCII("Legacy"); |
| 823 for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { |
| 824 SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); |
| 825 const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; |
| 826 FilePath local_data_path = new_root.Append(test_case.path); |
| 827 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 828 base::PlatformFileInfo ofsfu_file_info; |
| 829 FilePath data_path; |
| 830 SCOPED_TRACE(testing::Message() << "Path is " << test_case.path); |
| 831 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 832 ofsfu()->GetFileInfo(context.get(), FilePath(test_case.path), |
| 833 &ofsfu_file_info, &data_path)); |
| 834 if (test_case.is_directory) { |
| 835 EXPECT_TRUE(ofsfu_file_info.is_directory); |
| 836 } else { |
| 837 base::PlatformFileInfo platform_file_info; |
| 838 SCOPED_TRACE(testing::Message() << "local_data_path is " << |
| 839 local_data_path.value()); |
| 840 ASSERT_TRUE(file_util::GetFileInfo(local_data_path, &platform_file_info)); |
| 841 EXPECT_EQ(test_case.data_file_size, platform_file_info.size); |
| 842 EXPECT_FALSE(platform_file_info.is_directory); |
| 843 scoped_ptr<FileSystemOperationContext> context(NewContext()); |
| 844 EXPECT_EQ(local_data_path, data_path); |
| 845 EXPECT_EQ(platform_file_info.size, ofsfu_file_info.size); |
| 846 EXPECT_FALSE(ofsfu_file_info.is_directory); |
| 847 } |
| 848 } |
| 849 } |
| 850 |
| 851 //bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox( |
| 852 // const GURL& origin_url, FileSystemType type, const FilePath& src_root) { |
| OLD | NEW |