| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 NULL /* quota_manager */, | 69 NULL /* quota_manager */, |
| 70 data_dir_.path(), | 70 data_dir_.path(), |
| 71 CreateAllowFileAccessOptions()); | 71 CreateAllowFileAccessOptions()); |
| 72 | 72 |
| 73 // For cross-FileUtil copy/move tests. | 73 // For cross-FileUtil copy/move tests. |
| 74 other_file_util_.reset(new LocalFileUtil()); | 74 other_file_util_.reset(new LocalFileUtil()); |
| 75 other_file_util_helper_.SetUp(file_system_context_, other_file_util_.get()); | 75 other_file_util_helper_.SetUp(file_system_context_, other_file_util_.get()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void TearDown() { | 78 void TearDown() { |
| 79 isolated_context()->RevokeIsolatedFileSystem(filesystem_id_); | 79 isolated_context()->RevokeFileSystem(filesystem_id_); |
| 80 other_file_util_helper_.TearDown(); | 80 other_file_util_helper_.TearDown(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 protected: | 83 protected: |
| 84 IsolatedContext* isolated_context() const { | 84 IsolatedContext* isolated_context() const { |
| 85 return IsolatedContext::GetInstance(); | 85 return IsolatedContext::GetInstance(); |
| 86 } | 86 } |
| 87 const FilePath& root_path() const { | 87 const FilePath& root_path() const { |
| 88 return data_dir_.path(); | 88 return data_dir_.path(); |
| 89 } | 89 } |
| 90 FileSystemContext* file_system_context() const { | 90 FileSystemContext* file_system_context() const { |
| 91 return file_system_context_.get(); | 91 return file_system_context_.get(); |
| 92 } | 92 } |
| 93 FileSystemFileUtil* file_util() const { return file_util_.get(); } | 93 FileSystemFileUtil* file_util() const { return file_util_.get(); } |
| 94 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); } | 94 FileSystemFileUtil* other_file_util() const { return other_file_util_.get(); } |
| 95 std::string filesystem_id() const { return filesystem_id_; } | 95 std::string filesystem_id() const { return filesystem_id_; } |
| 96 | 96 |
| 97 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) { | 97 FilePath GetTestCasePlatformPath(const FilePath::StringType& path) { |
| 98 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path). | 98 return toplevel_root_map_[GetTopLevelPath(FilePath(path))].Append(path). |
| 99 NormalizePathSeparators(); | 99 NormalizePathSeparators(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 FileSystemURL GetFileSystemURL(const FilePath& path) const { | 102 FileSystemURL GetFileSystemURL(const FilePath& path) const { |
| 103 FilePath virtual_path = isolated_context()->CreateVirtualPath( | 103 FilePath virtual_path = isolated_context()->CreateVirtualRootPath( |
| 104 filesystem_id(), path); | 104 filesystem_id()).Append(path); |
| 105 return FileSystemURL(GURL("http://example.com"), | 105 return FileSystemURL(GURL("http://example.com"), |
| 106 kFileSystemTypeIsolated, | 106 kFileSystemTypeIsolated, |
| 107 virtual_path); | 107 virtual_path); |
| 108 } | 108 } |
| 109 | 109 |
| 110 FileSystemURL GetOtherFileSystemURL(const FilePath& path) { | 110 FileSystemURL GetOtherFileSystemURL(const FilePath& path) { |
| 111 return other_file_util_helper_.CreateURL(path); | 111 return other_file_util_helper_.CreateURL(path); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, | 114 void VerifyFilesHaveSameContent(FileSystemFileUtil* file_util1, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 scoped_ptr<FileSystemOperationContext> GetOperationContext() { | 187 scoped_ptr<FileSystemOperationContext> GetOperationContext() { |
| 188 return make_scoped_ptr( | 188 return make_scoped_ptr( |
| 189 new FileSystemOperationContext(file_system_context())).Pass(); | 189 new FileSystemOperationContext(file_system_context())).Pass(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 |
| 193 private: | 193 private: |
| 194 void SimulateDropFiles() { | 194 void SimulateDropFiles() { |
| 195 size_t root_path_index = 0; | 195 size_t root_path_index = 0; |
| 196 | 196 |
| 197 std::set<FilePath> toplevels; | 197 std::vector<IsolatedContext::FileInfo> toplevels; |
| 198 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 198 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
| 199 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 199 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
| 200 FilePath path(test_case.path); | 200 FilePath path(test_case.path); |
| 201 FilePath toplevel = GetTopLevelPath(path); | 201 FilePath toplevel = GetTopLevelPath(path); |
| 202 | 202 |
| 203 // We create the test case files under one of the kRootPaths | 203 // We create the test case files under one of the kRootPaths |
| 204 // to simulate a drop with multiple directories. | 204 // to simulate a drop with multiple directories. |
| 205 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { | 205 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { |
| 206 FilePath root = root_path().Append( | 206 FilePath root = root_path().Append( |
| 207 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); | 207 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); |
| 208 toplevel_root_map_[toplevel] = root; | 208 toplevel_root_map_[toplevel] = root; |
| 209 toplevels.insert(root.Append(path)); | 209 path = root.Append(path); |
| 210 toplevels.push_back(IsolatedContext::FileInfo( |
| 211 IsolatedContext::GetNameForPath(path), path)); |
| 210 } | 212 } |
| 211 | 213 |
| 212 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); | 214 test::SetUpOneTestCase(toplevel_root_map_[toplevel], test_case); |
| 213 } | 215 } |
| 214 | 216 |
| 215 // Register the toplevel entries. | 217 // Register the toplevel entries. |
| 216 filesystem_id_ = isolated_context()->RegisterIsolatedFileSystem(toplevels); | 218 filesystem_id_ = isolated_context()->RegisterFileSystem(toplevels); |
| 217 } | 219 } |
| 218 | 220 |
| 219 ScopedTempDir data_dir_; | 221 ScopedTempDir data_dir_; |
| 220 MessageLoop message_loop_; | 222 MessageLoop message_loop_; |
| 221 std::string filesystem_id_; | 223 std::string filesystem_id_; |
| 222 scoped_refptr<FileSystemContext> file_system_context_; | 224 scoped_refptr<FileSystemContext> file_system_context_; |
| 223 std::map<FilePath, FilePath> toplevel_root_map_; | 225 std::map<FilePath, FilePath> toplevel_root_map_; |
| 224 scoped_ptr<IsolatedFileUtil> file_util_; | 226 scoped_ptr<IsolatedFileUtil> file_util_; |
| 225 scoped_ptr<LocalFileUtil> other_file_util_; | 227 scoped_ptr<LocalFileUtil> other_file_util_; |
| 226 FileSystemTestOriginHelper other_file_util_helper_; | 228 FileSystemTestOriginHelper other_file_util_helper_; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { | 349 TEST_F(IsolatedFileUtilTest, GetLocalFilePathTest) { |
| 348 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 350 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
| 349 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 351 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
| 350 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); | 352 FileSystemURL url = GetFileSystemURL(FilePath(test_case.path)); |
| 351 | 353 |
| 352 FileSystemOperationContext context(file_system_context()); | 354 FileSystemOperationContext context(file_system_context()); |
| 353 | 355 |
| 354 FilePath local_file_path; | 356 FilePath local_file_path; |
| 355 EXPECT_EQ(base::PLATFORM_FILE_OK, | 357 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 356 file_util()->GetLocalFilePath(&context, url, &local_file_path)); | 358 file_util()->GetLocalFilePath(&context, url, &local_file_path)); |
| 357 EXPECT_EQ(GetTestCasePlatformPath(test_case.path), local_file_path); | 359 EXPECT_EQ(GetTestCasePlatformPath(test_case.path).value(), |
| 360 local_file_path.value()); |
| 358 } | 361 } |
| 359 } | 362 } |
| 360 | 363 |
| 361 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { | 364 TEST_F(IsolatedFileUtilTest, CopyOutFileTest) { |
| 362 scoped_ptr<FileSystemOperationContext> context( | 365 scoped_ptr<FileSystemOperationContext> context( |
| 363 new FileSystemOperationContext(file_system_context())); | 366 new FileSystemOperationContext(file_system_context())); |
| 364 FileSystemURL root_url = GetFileSystemURL(FilePath()); | 367 FileSystemURL root_url = GetFileSystemURL(FilePath()); |
| 365 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | 368 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
| 366 file_util()->CreateFileEnumerator(context.get(), | 369 file_util()->CreateFileEnumerator(context.get(), |
| 367 root_url, | 370 root_url, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 EXPECT_EQ(base::PLATFORM_FILE_OK, | 526 EXPECT_EQ(base::PLATFORM_FILE_OK, |
| 524 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 527 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
| 525 ASSERT_EQ(base::PLATFORM_FILE_OK, | 528 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 526 file_util()->GetFileInfo(GetOperationContext().get(), url, | 529 file_util()->GetFileInfo(GetOperationContext().get(), url, |
| 527 &info, &platform_path)); | 530 &info, &platform_path)); |
| 528 EXPECT_EQ(999, info.size); | 531 EXPECT_EQ(999, info.size); |
| 529 } | 532 } |
| 530 } | 533 } |
| 531 | 534 |
| 532 } // namespace fileapi | 535 } // namespace fileapi |
| OLD | NEW |