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