| 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 <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 FILE_PATH_LITERAL("b/c"), | 43 FILE_PATH_LITERAL("b/c"), |
| 44 FILE_PATH_LITERAL("etc"), | 44 FILE_PATH_LITERAL("etc"), |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 FilePath GetTopLevelPath(const FilePath& path) { | 47 FilePath GetTopLevelPath(const FilePath& path) { |
| 48 std::vector<FilePath::StringType> components; | 48 std::vector<FilePath::StringType> components; |
| 49 path.GetComponents(&components); | 49 path.GetComponents(&components); |
| 50 return FilePath(components[0]); | 50 return FilePath(components[0]); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool IsDirectoryEmpty(FileSystemOperationContext* context, |
| 54 FileSystemFileUtil* file_util, |
| 55 const FileSystemURL& url) { |
| 56 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum = |
| 57 file_util->CreateFileEnumerator(context, url, false /* recursive */); |
| 58 return file_enum->Next().empty(); |
| 59 } |
| 60 |
| 53 } // namespace | 61 } // namespace |
| 54 | 62 |
| 55 // TODO(kinuko): we should have separate tests for DraggedFileUtil and | 63 // TODO(kinuko): we should have separate tests for DraggedFileUtil and |
| 56 // IsolatedFileUtil. | 64 // IsolatedFileUtil. |
| 57 class IsolatedFileUtilTest : public testing::Test { | 65 class IsolatedFileUtilTest : public testing::Test { |
| 58 public: | 66 public: |
| 59 IsolatedFileUtilTest() {} | 67 IsolatedFileUtilTest() {} |
| 60 | 68 |
| 61 void SetUp() { | 69 void SetUp() { |
| 62 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 70 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 true /* recursive */); | 194 true /* recursive */); |
| 187 | 195 |
| 188 while (!(current = file_enum2->Next()).empty()) { | 196 while (!(current = file_enum2->Next()).empty()) { |
| 189 FilePath relative; | 197 FilePath relative; |
| 190 root_path2.AppendRelativePath(current, &relative); | 198 root_path2.AppendRelativePath(current, &relative); |
| 191 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); | 199 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); |
| 192 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); | 200 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); |
| 193 if (file_enum2->IsDirectory()) { | 201 if (file_enum2->IsDirectory()) { |
| 194 FileSystemOperationContext context1(file_system_context()); | 202 FileSystemOperationContext context1(file_system_context()); |
| 195 FileSystemOperationContext context2(file_system_context()); | 203 FileSystemOperationContext context2(file_system_context()); |
| 196 EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, url1), | 204 EXPECT_EQ(IsDirectoryEmpty(&context1, file_util1, url1), |
| 197 file_util2->IsDirectoryEmpty(&context2, url2)); | 205 IsDirectoryEmpty(&context2, file_util2, url2)); |
| 198 continue; | 206 continue; |
| 199 } | 207 } |
| 200 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); | 208 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); |
| 201 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); | 209 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); |
| 202 } | 210 } |
| 203 } | 211 } |
| 204 | 212 |
| 205 scoped_ptr<FileSystemOperationContext> GetOperationContext() { | 213 scoped_ptr<FileSystemOperationContext> GetOperationContext() { |
| 206 return make_scoped_ptr( | 214 return make_scoped_ptr( |
| 207 new FileSystemOperationContext(file_system_context())).Pass(); | 215 new FileSystemOperationContext(file_system_context())).Pass(); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 EXPECT_EQ(base::PLATFORM_FILE_OK, | 515 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 508 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 516 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
| 509 ASSERT_EQ(base::PLATFORM_FILE_OK, | 517 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 510 file_util()->GetFileInfo(GetOperationContext().get(), url, | 518 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 511 &info, &platform_path)); | 519 &info, &platform_path)); |
| 512 EXPECT_EQ(999, info.size); | 520 EXPECT_EQ(999, info.size); |
| 513 } | 521 } |
| 514 } | 522 } |
| 515 | 523 |
| 516 } // namespace fileapi | 524 } // namespace fileapi |
| OLD | NEW |