| 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 : other_file_util_helper_(GURL("http://foo/"), kFileSystemTypeTest) {} | 68 : other_file_util_helper_(GURL("http://foo/"), kFileSystemTypeTest) {} |
| 61 | 69 |
| 62 void SetUp() { | 70 void SetUp() { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 true /* recursive */); | 197 true /* recursive */); |
| 190 | 198 |
| 191 while (!(current = file_enum2->Next()).empty()) { | 199 while (!(current = file_enum2->Next()).empty()) { |
| 192 FilePath relative; | 200 FilePath relative; |
| 193 root_path2.AppendRelativePath(current, &relative); | 201 root_path2.AppendRelativePath(current, &relative); |
| 194 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); | 202 FileSystemURL url1 = root1.WithPath(root_path1.Append(relative)); |
| 195 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); | 203 FileSystemURL url2 = root2.WithPath(root_path2.Append(relative)); |
| 196 if (file_enum2->IsDirectory()) { | 204 if (file_enum2->IsDirectory()) { |
| 197 FileSystemOperationContext context1(file_system_context()); | 205 FileSystemOperationContext context1(file_system_context()); |
| 198 FileSystemOperationContext context2(file_system_context()); | 206 FileSystemOperationContext context2(file_system_context()); |
| 199 EXPECT_EQ(file_util1->IsDirectoryEmpty(&context1, url1), | 207 EXPECT_EQ(IsDirectoryEmpty(&context1, file_util1, url1), |
| 200 file_util2->IsDirectoryEmpty(&context2, url2)); | 208 IsDirectoryEmpty(&context2, file_util2, url2)); |
| 201 continue; | 209 continue; |
| 202 } | 210 } |
| 203 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); | 211 EXPECT_TRUE(file_set1.find(relative) != file_set1.end()); |
| 204 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); | 212 VerifyFilesHaveSameContent(file_util1, file_util2, url1, url2); |
| 205 } | 213 } |
| 206 } | 214 } |
| 207 | 215 |
| 208 scoped_ptr<FileSystemOperationContext> GetOperationContext() { | 216 scoped_ptr<FileSystemOperationContext> GetOperationContext() { |
| 209 return make_scoped_ptr( | 217 return make_scoped_ptr( |
| 210 new FileSystemOperationContext(file_system_context())).Pass(); | 218 new FileSystemOperationContext(file_system_context())).Pass(); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 EXPECT_EQ(base::PLATFORM_FILE_OK, | 518 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 511 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 519 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
| 512 ASSERT_EQ(base::PLATFORM_FILE_OK, | 520 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 513 file_util()->GetFileInfo(GetOperationContext().get(), url, | 521 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 514 &info, &platform_path)); | 522 &info, &platform_path)); |
| 515 EXPECT_EQ(999, info.size); | 523 EXPECT_EQ(999, info.size); |
| 516 } | 524 } |
| 517 } | 525 } |
| 518 | 526 |
| 519 } // namespace fileapi | 527 } // namespace fileapi |
| OLD | NEW |