| 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 <map> | 5 #include <map> |
| 6 #include <queue> |
| 6 #include <set> | 7 #include <set> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
| 15 #include "base/time.h" | 16 #include "base/time.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webkit/fileapi/async_file_test_helper.h" |
| 17 #include "webkit/fileapi/external_mount_points.h" | 19 #include "webkit/fileapi/external_mount_points.h" |
| 18 #include "webkit/fileapi/file_system_context.h" | 20 #include "webkit/fileapi/file_system_context.h" |
| 19 #include "webkit/fileapi/file_system_operation_context.h" | 21 #include "webkit/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/fileapi/file_system_task_runners.h" | 22 #include "webkit/fileapi/file_system_task_runners.h" |
| 21 #include "webkit/fileapi/file_util_helper.h" | |
| 22 #include "webkit/fileapi/isolated_context.h" | 23 #include "webkit/fileapi/isolated_context.h" |
| 23 #include "webkit/fileapi/isolated_file_util.h" | 24 #include "webkit/fileapi/isolated_file_util.h" |
| 24 #include "webkit/fileapi/local_file_system_operation.h" | 25 #include "webkit/fileapi/local_file_system_operation.h" |
| 25 #include "webkit/fileapi/local_file_system_test_helper.h" | 26 #include "webkit/fileapi/local_file_system_test_helper.h" |
| 26 #include "webkit/fileapi/local_file_util.h" | 27 #include "webkit/fileapi/local_file_util.h" |
| 27 #include "webkit/fileapi/mock_file_system_options.h" | 28 #include "webkit/fileapi/mock_file_system_options.h" |
| 28 #include "webkit/fileapi/native_file_util.h" | 29 #include "webkit/fileapi/native_file_util.h" |
| 29 #include "webkit/fileapi/test_file_set.h" | 30 #include "webkit/fileapi/test_file_set.h" |
| 30 #include "webkit/quota/mock_special_storage_policy.h" | 31 #include "webkit/quota/mock_special_storage_policy.h" |
| 31 | 32 |
| 32 using file_util::FileEnumerator; | 33 using file_util::FileEnumerator; |
| 33 | 34 |
| 34 namespace fileapi { | 35 namespace fileapi { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 39 typedef AsyncFileTestHelper::FileEntryList FileEntryList; |
| 40 |
| 38 // Used in IsolatedFileUtilTest::SimulateDropFiles(). | 41 // Used in IsolatedFileUtilTest::SimulateDropFiles(). |
| 39 // Random root paths in which we create each file/directory of the | 42 // Random root paths in which we create each file/directory of the |
| 40 // RegularTestCases (so that we can simulate a drop with files/directories | 43 // RegularTestCases (so that we can simulate a drop with files/directories |
| 41 // from multiple directories). | 44 // from multiple directories). |
| 42 static const base::FilePath::CharType* kRootPaths[] = { | 45 static const base::FilePath::CharType* kRootPaths[] = { |
| 43 FILE_PATH_LITERAL("a"), | 46 FILE_PATH_LITERAL("a"), |
| 44 FILE_PATH_LITERAL("b/c"), | 47 FILE_PATH_LITERAL("b/c"), |
| 45 FILE_PATH_LITERAL("etc"), | 48 FILE_PATH_LITERAL("etc"), |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 base::FilePath GetTopLevelPath(const base::FilePath& path) { | 51 base::FilePath GetTopLevelPath(const base::FilePath& path) { |
| 49 std::vector<base::FilePath::StringType> components; | 52 std::vector<base::FilePath::StringType> components; |
| 50 path.GetComponents(&components); | 53 path.GetComponents(&components); |
| 51 return base::FilePath(components[0]); | 54 return base::FilePath(components[0]); |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool IsDirectoryEmpty(FileSystemOperationContext* context, | 57 bool IsDirectoryEmpty(FileSystemContext* context, const FileSystemURL& url) { |
| 55 FileSystemFileUtil* file_util, | 58 FileEntryList entries; |
| 56 const FileSystemURL& url) { | 59 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 57 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum = | 60 AsyncFileTestHelper::ReadDirectory(context, url, &entries)); |
| 58 file_util->CreateFileEnumerator(context, url, false /* recursive */); | 61 return entries.empty(); |
| 59 return file_enum->Next().empty(); | 62 } |
| 63 |
| 64 FileSystemURL GetEntryURL(FileSystemContext* file_system_context, |
| 65 const FileSystemURL& dir, |
| 66 const FilePath::StringType& name) { |
| 67 return file_system_context->CreateCrackedFileSystemURL( |
| 68 dir.origin(), |
| 69 dir.mount_type(), |
| 70 dir.virtual_path().Append(name)); |
| 71 } |
| 72 |
| 73 FilePath GetRelativeVirtualPath(const FileSystemURL& root, |
| 74 const FileSystemURL& url) { |
| 75 if (root.virtual_path().empty()) |
| 76 return url.virtual_path(); |
| 77 FilePath relative; |
| 78 const bool success = root.virtual_path().AppendRelativePath( |
| 79 url.virtual_path(), &relative); |
| 80 DCHECK(success); |
| 81 return relative; |
| 82 } |
| 83 |
| 84 FileSystemURL GetOtherURL(FileSystemContext* file_system_context, |
| 85 const FileSystemURL& root, |
| 86 const FileSystemURL& other_root, |
| 87 const FileSystemURL& url) { |
| 88 return file_system_context->CreateCrackedFileSystemURL( |
| 89 other_root.origin(), |
| 90 other_root.mount_type(), |
| 91 other_root.virtual_path().Append(GetRelativeVirtualPath(root, url))); |
| 60 } | 92 } |
| 61 | 93 |
| 62 } // namespace | 94 } // namespace |
| 63 | 95 |
| 64 // TODO(kinuko): we should have separate tests for DraggedFileUtil and | 96 // TODO(kinuko): we should have separate tests for DraggedFileUtil and |
| 65 // IsolatedFileUtil. | 97 // IsolatedFileUtil. |
| 66 class IsolatedFileUtilTest : public testing::Test { | 98 class IsolatedFileUtilTest : public testing::Test { |
| 67 public: | 99 public: |
| 68 IsolatedFileUtilTest() | 100 IsolatedFileUtilTest() {} |
| 69 : other_file_util_helper_(GURL("http://foo/"), kFileSystemTypeTest) {} | |
| 70 | 101 |
| 71 virtual void SetUp() { | 102 virtual void SetUp() { |
| 72 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 103 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 73 ASSERT_TRUE(partition_dir_.CreateUniqueTempDir()); | 104 ASSERT_TRUE(partition_dir_.CreateUniqueTempDir()); |
| 74 file_util_.reset(new DraggedFileUtil()); | 105 file_util_.reset(new DraggedFileUtil()); |
| 75 | 106 |
| 76 // Register the files/directories of RegularTestCases (with random | 107 // Register the files/directories of RegularTestCases (with random |
| 77 // root paths) as dropped files. | 108 // root paths) as dropped files. |
| 78 SimulateDropFiles(); | 109 SimulateDropFiles(); |
| 79 | 110 |
| 80 file_system_context_ = new FileSystemContext( | 111 file_system_context_ = new FileSystemContext( |
| 81 FileSystemTaskRunners::CreateMockTaskRunners(), | 112 FileSystemTaskRunners::CreateMockTaskRunners(), |
| 82 ExternalMountPoints::CreateRefCounted().get(), | 113 ExternalMountPoints::CreateRefCounted().get(), |
| 83 make_scoped_refptr(new quota::MockSpecialStoragePolicy()), | 114 make_scoped_refptr(new quota::MockSpecialStoragePolicy()), |
| 84 NULL /* quota_manager */, | 115 NULL /* quota_manager */, |
| 85 partition_dir_.path(), | 116 partition_dir_.path(), |
| 86 CreateAllowFileAccessOptions()); | 117 CreateAllowFileAccessOptions()); |
| 87 | 118 |
| 88 // For cross-FileUtil copy/move tests. | |
| 89 other_file_util_helper_.SetUp(file_system_context_); | |
| 90 | |
| 91 isolated_context()->AddReference(filesystem_id_); | 119 isolated_context()->AddReference(filesystem_id_); |
| 92 } | 120 } |
| 93 | 121 |
| 94 virtual void TearDown() { | 122 virtual void TearDown() { |
| 95 isolated_context()->RemoveReference(filesystem_id_); | 123 isolated_context()->RemoveReference(filesystem_id_); |
| 96 other_file_util_helper_.TearDown(); | |
| 97 } | 124 } |
| 98 | 125 |
| 99 protected: | 126 protected: |
| 100 IsolatedContext* isolated_context() const { | 127 IsolatedContext* isolated_context() const { |
| 101 return IsolatedContext::GetInstance(); | 128 return IsolatedContext::GetInstance(); |
| 102 } | 129 } |
| 103 const base::FilePath& root_path() const { | 130 const base::FilePath& root_path() const { |
| 104 return data_dir_.path(); | 131 return data_dir_.path(); |
| 105 } | 132 } |
| 106 FileSystemContext* file_system_context() const { | 133 FileSystemContext* file_system_context() const { |
| 107 return file_system_context_.get(); | 134 return file_system_context_.get(); |
| 108 } | 135 } |
| 109 FileSystemFileUtil* file_util() const { return file_util_.get(); } | 136 FileSystemFileUtil* file_util() const { return file_util_.get(); } |
| 110 FileSystemFileUtil* other_file_util() const { | |
| 111 return other_file_util_helper_.file_util(); | |
| 112 } | |
| 113 std::string filesystem_id() const { return filesystem_id_; } | 137 std::string filesystem_id() const { return filesystem_id_; } |
| 114 | 138 |
| 115 base::FilePath GetTestCasePlatformPath(const base::FilePath::StringType& path)
{ | 139 base::FilePath GetTestCasePlatformPath( |
| 116 return toplevel_root_map_[GetTopLevelPath(base::FilePath(path))].Append(path
). | 140 const base::FilePath::StringType& path) { |
| 117 NormalizePathSeparators(); | 141 return toplevel_root_map_[GetTopLevelPath(base::FilePath(path))] |
| 142 .Append(path).NormalizePathSeparators(); |
| 118 } | 143 } |
| 119 | 144 |
| 120 base::FilePath GetTestCaseLocalPath(const base::FilePath& path) { | 145 base::FilePath GetTestCaseLocalPath(const base::FilePath& path) { |
| 121 base::FilePath relative; | 146 base::FilePath relative; |
| 122 if (data_dir_.path().AppendRelativePath(path, &relative)) | 147 if (data_dir_.path().AppendRelativePath(path, &relative)) |
| 123 return relative; | 148 return relative; |
| 124 return path; | 149 return path; |
| 125 } | 150 } |
| 126 | 151 |
| 127 FileSystemURL GetFileSystemURL(const base::FilePath& path) const { | 152 FileSystemURL GetFileSystemURL(const base::FilePath& path) const { |
| 128 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath( | 153 base::FilePath virtual_path = isolated_context()->CreateVirtualRootPath( |
| 129 filesystem_id()).Append(path); | 154 filesystem_id()).Append(path); |
| 130 return file_system_context_->CreateCrackedFileSystemURL( | 155 return file_system_context_->CreateCrackedFileSystemURL( |
| 131 GURL("http://example.com"), | 156 GURL("http://example.com"), |
| 132 kFileSystemTypeIsolated, | 157 kFileSystemTypeIsolated, |
| 133 virtual_path); | 158 virtual_path); |
| 134 } | 159 } |
| 135 | 160 |
| 136 FileSystemURL GetOtherFileSystemURL(const base::FilePath& path) { | 161 FileSystemURL GetOtherFileSystemURL(const base::FilePath& path) const { |
| 137 return other_file_util_helper_.CreateURL(GetTestCaseLocalPath(path)); | 162 return file_system_context()->CreateCrackedFileSystemURL( |
| 163 GURL("http://example.com"), |
| 164 kFileSystemTypeTemporary, |
| 165 FilePath().AppendASCII("dest").Append(path)); |
| 138 } | 166 } |
| 139 | 167 |
| 140 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, | 168 void VerifyFilesHaveSameContent(const FileSystemURL& url1, |
| 141 FileSystemFileUtil* file_util2, | |
| 142 const FileSystemURL& url1, | |
| 143 const FileSystemURL& url2) { | 169 const FileSystemURL& url2) { |
| 144 scoped_ptr<FileSystemOperationContext> context; | |
| 145 | |
| 146 // Get the file info for url1. | 170 // Get the file info for url1. |
| 147 base::PlatformFileInfo info1; | 171 base::PlatformFileInfo info1; |
| 148 base::FilePath platform_path1; | 172 FilePath platform_path1; |
| 149 context.reset(new FileSystemOperationContext(file_system_context())); | |
| 150 ASSERT_EQ(base::PLATFORM_FILE_OK, | 173 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 151 file_util1->GetFileInfo(context.get(), url1, | 174 AsyncFileTestHelper::GetMetadata( |
| 152 &info1, &platform_path1)); | 175 file_system_context(), url1, &info1, &platform_path1)); |
| 153 | 176 |
| 154 // Get the file info for url2. | 177 // Get the file info for url2. |
| 155 base::PlatformFileInfo info2; | 178 base::PlatformFileInfo info2; |
| 156 base::FilePath platform_path2; | 179 base::FilePath platform_path2; |
| 157 context.reset(new FileSystemOperationContext(file_system_context())); | |
| 158 ASSERT_EQ(base::PLATFORM_FILE_OK, | 180 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 159 file_util2->GetFileInfo(context.get(), url2, | 181 AsyncFileTestHelper::GetMetadata( |
| 160 &info2, &platform_path2)); | 182 file_system_context(), url2, &info2, &platform_path2)); |
| 161 | 183 |
| 162 // See if file info matches with the other one. | 184 // See if file info matches with the other one. |
| 163 EXPECT_EQ(info1.is_directory, info2.is_directory); | 185 EXPECT_EQ(info1.is_directory, info2.is_directory); |
| 164 EXPECT_EQ(info1.size, info2.size); | 186 EXPECT_EQ(info1.size, info2.size); |
| 165 EXPECT_EQ(info1.is_symbolic_link, info2.is_symbolic_link); | 187 EXPECT_EQ(info1.is_symbolic_link, info2.is_symbolic_link); |
| 166 EXPECT_NE(platform_path1, platform_path2); | 188 EXPECT_NE(platform_path1, platform_path2); |
| 167 | 189 |
| 168 std::string content1, content2; | 190 std::string content1, content2; |
| 169 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1)); | 191 EXPECT_TRUE(file_util::ReadFileToString(platform_path1, &content1)); |
| 170 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2)); | 192 EXPECT_TRUE(file_util::ReadFileToString(platform_path2, &content2)); |
| 171 EXPECT_EQ(content1, content2); | 193 EXPECT_EQ(content1, content2); |
| 172 } | 194 } |
| 173 | 195 |
| 174 void VerifyDirectoriesHaveSameContent(FileSystemFileUtil* file_util1, | 196 void VerifyDirectoriesHaveSameContent(const FileSystemURL& root1, |
| 175 FileSystemFileUtil* file_util2, | |
| 176 const FileSystemURL& root1, | |
| 177 const FileSystemURL& root2) { | 197 const FileSystemURL& root2) { |
| 178 scoped_ptr<FileSystemOperationContext> context; | |
| 179 base::FilePath root_path1 = root1.path(); | 198 base::FilePath root_path1 = root1.path(); |
| 180 base::FilePath root_path2 = root2.path(); | 199 base::FilePath root_path2 = root2.path(); |
| 181 | 200 |
| 182 context.reset(new FileSystemOperationContext(file_system_context())); | 201 FileEntryList entries; |
| 183 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum1 = | 202 std::queue<FileSystemURL> directories; |
| 184 file_util1->CreateFileEnumerator(context.get(), root1, | |
| 185 true /* recursive */); | |
| 186 | 203 |
| 187 base::FilePath current; | 204 directories.push(root1); |
| 188 std::set<base::FilePath> file_set1; | 205 std::set<base::FilePath> file_set1; |
| 189 while (!(current = file_enum1->Next()).empty()) { | 206 while (!directories.empty()) { |
| 190 if (file_enum1->IsDirectory()) | 207 FileSystemURL dir = directories.front(); |
| 191 continue; | 208 directories.pop(); |
| 192 base::FilePath relative; | 209 |
| 193 root_path1.AppendRelativePath(current, &relative); | 210 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 194 file_set1.insert(relative); | 211 AsyncFileTestHelper::ReadDirectory( |
| 212 file_system_context(), dir, &entries)); |
| 213 for (size_t i = 0; i < entries.size(); ++i) { |
| 214 FileSystemURL url = GetEntryURL(file_system_context(), |
| 215 dir, entries[i].name); |
| 216 if (entries[i].is_directory) { |
| 217 directories.push(url); |
| 218 continue; |
| 219 } |
| 220 file_set1.insert(GetRelativeVirtualPath(root1, url)); |
| 221 } |
| 195 } | 222 } |
| 196 | 223 |
| 197 context.reset(new FileSystemOperationContext(file_system_context())); | 224 directories.push(root2); |
| 198 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum2 = | 225 while (!directories.empty()) { |
| 199 file_util2->CreateFileEnumerator(context.get(), root2, | 226 FileSystemURL dir = directories.front(); |
| 200 true /* recursive */); | 227 directories.pop(); |
| 201 | 228 |
| 202 while (!(current = file_enum2->Next()).empty()) { | 229 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 203 base::FilePath relative; | 230 AsyncFileTestHelper::ReadDirectory( |
| 204 root_path2.AppendRelativePath(current, &relative); | 231 file_system_context(), dir, &entries)); |
| 205 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); | 232 for (size_t i = 0; i < entries.size(); ++i) { |
| 206 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); | 233 FileSystemURL url2 = GetEntryURL(file_system_context(), |
| 207 if (file_enum2->IsDirectory()) { | 234 dir, entries[i].name); |
| 208 FileSystemOperationContext context1(file_system_context()); | 235 FileSystemURL url1 = GetOtherURL(file_system_context(), |
| 209 FileSystemOperationContext context2(file_system_context()); | 236 root2, root1, url2); |
| 210 EXPECT_EQ(IsDirectoryEmpty(&context1, file_util1, url1), | 237 if (entries[i].is_directory) { |
| 211 IsDirectoryEmpty(&context2, file_util2, url2)); | 238 directories.push(url2); |
| 212 continue; | 239 EXPECT_EQ(IsDirectoryEmpty(file_system_context(), url1), |
| 240 IsDirectoryEmpty(file_system_context(), url2)); |
| 241 continue; |
| 242 } |
| 243 base::FilePath relative = GetRelativeVirtualPath(root2, url2); |
| 244 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); |
| 245 VerifyFilesHaveSameContent(url1, url2); |
| 213 } | 246 } |
| 214 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); | |
| 215 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); | |
| 216 } | 247 } |
| 217 } | 248 } |
| 218 | 249 |
| 219 scoped_ptr<FileSystemOperationContext> GetOperationContext() { | 250 scoped_ptr<FileSystemOperationContext> GetOperationContext() { |
| 220 return make_scoped_ptr( | 251 return make_scoped_ptr( |
| 221 new FileSystemOperationContext(file_system_context())).Pass(); | 252 new FileSystemOperationContext(file_system_context())).Pass(); |
| 222 } | 253 } |
| 223 | 254 |
| 224 | 255 |
| 225 private: | 256 private: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 248 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); | 279 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(toplevels); |
| 249 } | 280 } |
| 250 | 281 |
| 251 base::ScopedTempDir data_dir_; | 282 base::ScopedTempDir data_dir_; |
| 252 base::ScopedTempDir partition_dir_; | 283 base::ScopedTempDir partition_dir_; |
| 253 MessageLoop message_loop_; | 284 MessageLoop message_loop_; |
| 254 std::string filesystem_id_; | 285 std::string filesystem_id_; |
| 255 scoped_refptr<FileSystemContext> file_system_context_; | 286 scoped_refptr<FileSystemContext> file_system_context_; |
| 256 std::map<base::FilePath, base::FilePath> toplevel_root_map_; | 287 std::map<base::FilePath, base::FilePath> toplevel_root_map_; |
| 257 scoped_ptr<IsolatedFileUtil> file_util_; | 288 scoped_ptr<IsolatedFileUtil> file_util_; |
| 258 LocalFileSystemTestOriginHelper other_file_util_helper_; | |
| 259 DISALLOW_COPY_AND_ASSIGN(IsolatedFileUtilTest); | 289 DISALLOW_COPY_AND_ASSIGN(IsolatedFileUtilTest); |
| 260 }; | 290 }; |
| 261 | 291 |
| 262 TEST_F(IsolatedFileUtilTest, BasicTest) { | 292 TEST_F(IsolatedFileUtilTest, BasicTest) { |
| 263 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 293 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
| 264 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); | 294 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i); |
| 265 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 295 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
| 266 | 296 |
| 267 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 297 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 268 | 298 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { | 359 TEST_F(IsolatedFileUtilTest, ReadDirectoryTest) { |
| 330 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 360 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
| 331 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 361 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
| 332 if (!test_case.is_directory) | 362 if (!test_case.is_directory) |
| 333 continue; | 363 continue; |
| 334 | 364 |
| 335 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i | 365 SCOPED_TRACE(testing::Message() << "Testing RegularTestCases " << i |
| 336 << ": " << test_case.path); | 366 << ": " << test_case.path); |
| 337 | 367 |
| 338 // Read entries in the directory to construct the expected results map. | 368 // Read entries in the directory to construct the expected results map. |
| 339 typedef std::map<base::FilePath::StringType, base::FileUtilProxy::Entry> Ent
ryMap; | 369 typedef std::map<base::FilePath::StringType, |
| 370 base::FileUtilProxy::Entry> EntryMap; |
| 340 EntryMap expected_entry_map; | 371 EntryMap expected_entry_map; |
| 341 | 372 |
| 342 FileEnumerator file_enum( | 373 FileEnumerator file_enum( |
| 343 GetTestCasePlatformPath(test_case.path), false /* not recursive */, | 374 GetTestCasePlatformPath(test_case.path), false /* not recursive */, |
| 344 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | 375 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); |
| 345 base::FilePath current; | 376 base::FilePath current; |
| 346 while (!(current = file_enum.Next()).empty()) { | 377 while (!(current = file_enum.Next()).empty()) { |
| 347 FileEnumerator::FindInfo file_info; | 378 FileEnumerator::FindInfo file_info; |
| 348 file_enum.GetFindInfo(&file_info); | 379 file_enum.GetFindInfo(&file_info); |
| 349 base::FileUtilProxy::Entry entry; | 380 base::FileUtilProxy::Entry entry; |
| 350 entry.is_directory = FileEnumerator::IsDirectory(file_info); | 381 entry.is_directory = FileEnumerator::IsDirectory(file_info); |
| 351 entry.name = current.BaseName().value(); | 382 entry.name = current.BaseName().value(); |
| 352 entry.size = FileEnumerator::GetFilesize(file_info); | 383 entry.size = FileEnumerator::GetFilesize(file_info); |
| 353 entry.last_modified_time = FileEnumerator::GetLastModifiedTime(file_info); | 384 entry.last_modified_time = FileEnumerator::GetLastModifiedTime(file_info); |
| 354 expected_entry_map[entry.name] = entry; | 385 expected_entry_map[entry.name] = entry; |
| 355 } | 386 } |
| 356 | 387 |
| 357 // Perform ReadDirectory in the isolated filesystem. | 388 // Perform ReadDirectory in the isolated filesystem. |
| 358 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 389 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| 359 std::vector<base::FileUtilProxy::Entry> entries; | 390 FileEntryList entries; |
| 360 FileSystemOperationContext context(file_system_context()); | |
| 361 ASSERT_EQ(base::PLATFORM_FILE_OK, | 391 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 362 FileUtilHelper::ReadDirectory( | 392 AsyncFileTestHelper::ReadDirectory( |
| 363 &context, file_util(), url, &entries)); | 393 file_system_context(), url, &entries)); |
| 364 | 394 |
| 365 EXPECT_EQ(expected_entry_map.size(), entries.size()); | 395 EXPECT_EQ(expected_entry_map.size(), entries.size()); |
| 366 for (size_t i = 0; i < entries.size(); ++i) { | 396 for (size_t i = 0; i < entries.size(); ++i) { |
| 367 const base::FileUtilProxy::Entry& entry = entries[i]; | 397 const base::FileUtilProxy::Entry& entry = entries[i]; |
| 368 EntryMap::iterator found = expected_entry_map.find(entry.name); | 398 EntryMap::iterator found = expected_entry_map.find(entry.name); |
| 369 EXPECT_TRUE(found != expected_entry_map.end()); | 399 EXPECT_TRUE(found != expected_entry_map.end()); |
| 370 EXPECT_EQ(found->second.name, entry.name); | 400 EXPECT_EQ(found->second.name, entry.name); |
| 371 EXPECT_EQ(found->second.is_directory, entry.is_directory); | 401 EXPECT_EQ(found->second.is_directory, entry.is_directory); |
| 372 EXPECT_EQ(found->second.size, entry.size); | 402 EXPECT_EQ(found->second.size, entry.size); |
| 373 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), | 403 EXPECT_EQ(found->second.last_modified_time.ToDoubleT(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 385 | 415 |
| 386 base::FilePath local_file_path; | 416 base::FilePath local_file_path; |
| 387 EXPECT_EQ(base::PLATFORM_FILE_OK, | 417 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 388 file_util()->GetLocalFilePath(&context, url, &local_file_path)); | 418 file_util()->GetLocalFilePath(&context, url, &local_file_path)); |
| 389 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), | 419 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), |
| 390 local_file_path.value()); | 420 local_file_path.value()); |
| 391 } | 421 } |
| 392 } | 422 } |
| 393 | 423 |
| 394 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { | 424 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { |
| 395 scoped_ptr<FileSystemOperationContext> context( | 425 FileSystemURL src_root = GetFileSystemURL(base::FilePath()); |
| 396 new FileSystemOperationContext(file_system_context())); | 426 FileSystemURL dest_root = GetOtherFileSystemURL(base::FilePath()); |
| 397 FileSystemURL root_url = GetFileSystemURL(base::FilePath()); | |
| 398 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | |
| 399 file_util()->CreateFileEnumerator(context.get(), | |
| 400 root_url, | |
| 401 true /* recursive */)); | |
| 402 base::FilePath current; | |
| 403 while (!(current = file_enum->Next()).empty()) { | |
| 404 if (file_enum->IsDirectory()) | |
| 405 continue; | |
| 406 | 427 |
| 407 SCOPED_TRACE(testing::Message() << "Testing file copy " | 428 FileEntryList entries; |
| 408 << current.value()); | 429 std::queue<FileSystemURL> directories; |
| 430 directories.push(src_root); |
| 409 | 431 |
| 410 FileSystemURL src_url = root_url.WithPath(current); | 432 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 411 FileSystemURL dest_url = GetOtherFileSystemURL(current); | 433 AsyncFileTestHelper::CreateDirectory(file_system_context(), |
| 434 dest_root)); |
| 412 | 435 |
| 413 // Create the parent directory of the destination. | 436 while (!directories.empty()) { |
| 414 context.reset(new FileSystemOperationContext(file_system_context())); | 437 FileSystemURL dir = directories.front(); |
| 438 directories.pop(); |
| 415 ASSERT_EQ(base::PLATFORM_FILE_OK, | 439 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 416 other_file_util()->CreateDirectory( | 440 AsyncFileTestHelper::ReadDirectory(file_system_context(), |
| 417 context.get(), | 441 dir, &entries)); |
| 418 GetOtherFileSystemURL(current.DirName()), | 442 for (size_t i = 0; i < entries.size(); ++i) { |
| 419 false /* exclusive */, | 443 FileSystemURL src_url = GetEntryURL(file_system_context(), |
| 420 true /* recursive */)); | 444 dir, entries[i].name); |
| 445 FileSystemURL dest_url = GetOtherURL(file_system_context(), |
| 446 src_root, dest_root, src_url); |
| 421 | 447 |
| 422 context.reset(new FileSystemOperationContext(file_system_context())); | 448 if (entries[i].is_directory) { |
| 423 ASSERT_EQ(base::PLATFORM_FILE_OK, | 449 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 424 FileUtilHelper::Copy( | 450 AsyncFileTestHelper::CreateDirectory(file_system_context(), |
| 425 context.get(), | 451 dest_url)); |
| 426 file_util(), other_file_util(), | 452 directories.push(src_url); |
| 427 src_url, dest_url)); | 453 continue; |
| 428 | 454 } |
| 429 VerifyFilesHaveSameContent(file_util(), other_file_util(), | 455 SCOPED_TRACE(testing::Message() << "Testing file copy " |
| 430 src_url, dest_url); | 456 << src_url.path().value()); |
| 457 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 458 AsyncFileTestHelper::Copy(file_system_context(), |
| 459 src_url, dest_url)); |
| 460 VerifyFilesHaveSameContent(src_url, dest_url); |
| 461 } |
| 431 } | 462 } |
| 432 } | 463 } |
| 433 | 464 |
| 434 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { | 465 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { |
| 435 scoped_ptr<FileSystemOperationContext> context( | 466 FileSystemURL src_root = GetFileSystemURL(base::FilePath()); |
| 436 new FileSystemOperationContext(file_system_context())); | 467 FileSystemURL dest_root = GetOtherFileSystemURL(base::FilePath()); |
| 437 FileSystemURL root_url = GetFileSystemURL(base::FilePath()); | 468 |
| 438 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | 469 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 439 file_util()->CreateFileEnumerator(context.get(), | 470 AsyncFileTestHelper::CreateDirectory(file_system_context(), |
| 440 root_url, | 471 dest_root)); |
| 441 false /* recursive */)); | 472 |
| 442 base::FilePath current; | 473 FileEntryList entries; |
| 443 while (!(current = file_enum->Next()).empty()) { | 474 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 444 if (!file_enum->IsDirectory()) | 475 AsyncFileTestHelper::ReadDirectory(file_system_context(), |
| 476 src_root, &entries)); |
| 477 for (size_t i = 0; i < entries.size(); ++i) { |
| 478 if (!entries[i].is_directory) |
| 445 continue; | 479 continue; |
| 446 | 480 FileSystemURL src_url = GetEntryURL(file_system_context(), |
| 447 SCOPED_TRACE(testing::Message() << "Testing directory copy " | 481 src_root, entries[i].name); |
| 448 << current.value()); | 482 FileSystemURL dest_url = GetOtherURL(file_system_context(), |
| 449 | 483 src_root, dest_root, src_url); |
| 450 FileSystemURL src_url = root_url.WithPath(current); | 484 SCOPED_TRACE(testing::Message() << "Testing file copy " |
| 451 FileSystemURL dest_url = GetOtherFileSystemURL(current); | 485 << src_url.path().value()); |
| 452 | |
| 453 // Create the parent directory of the destination. | |
| 454 context.reset(new FileSystemOperationContext(file_system_context())); | |
| 455 ASSERT_EQ(base::PLATFORM_FILE_OK, | 486 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 456 other_file_util()->CreateDirectory( | 487 AsyncFileTestHelper::Copy(file_system_context(), |
| 457 context.get(), | 488 src_url, dest_url)); |
| 458 GetOtherFileSystemURL(current.DirName()), | 489 VerifyDirectoriesHaveSameContent(src_url, dest_url); |
| 459 false /* exclusive */, | |
| 460 true /* recursive */)); | |
| 461 | |
| 462 context.reset(new FileSystemOperationContext(file_system_context())); | |
| 463 ASSERT_EQ(base::PLATFORM_FILE_OK, | |
| 464 FileUtilHelper::Copy( | |
| 465 context.get(), | |
| 466 file_util(), other_file_util(), | |
| 467 src_url, dest_url)); | |
| 468 | |
| 469 VerifyDirectoriesHaveSameContent(file_util(), other_file_util(), | |
| 470 src_url, dest_url); | |
| 471 } | 490 } |
| 472 } | 491 } |
| 473 | 492 |
| 474 TEST_F(IsolatedFileUtilTest, TouchTest) { | 493 TEST_F(IsolatedFileUtilTest, TouchTest) { |
| 475 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 494 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
| 476 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 495 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
| 477 if (test_case.is_directory) | 496 if (test_case.is_directory) |
| 478 continue; | 497 continue; |
| 479 SCOPED_TRACE(testing::Message() << test_case.path); | 498 SCOPED_TRACE(testing::Message() << test_case.path); |
| 480 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); | 499 FileSystemURL url = GetFileSystemURL(base::FilePath(test_case.path)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 EXPECT_EQ(base::PLATFORM_FILE_OK, | 540 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 522 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 541 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
| 523 ASSERT_EQ(base::PLATFORM_FILE_OK, | 542 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 524 file_util()->GetFileInfo(GetOperationContext().get(), url, | 543 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 525 &info, &platform_path)); | 544 &info, &platform_path)); |
| 526 EXPECT_EQ(999, info.size); | 545 EXPECT_EQ(999, info.size); |
| 527 } | 546 } |
| 528 } | 547 } |
| 529 | 548 |
| 530 } // namespace fileapi | 549 } // namespace fileapi |
| OLD | NEW |