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 }; | 43 }; |
44 | 44 |
45 FilePath GetTopLevelPath(const FilePath& path) { | 45 FilePath GetTopLevelPath(const FilePath& path) { |
46 std::vector<FilePath::StringType> components; | 46 std::vector<FilePath::StringType> components; |
47 path.GetComponents(&components); | 47 path.GetComponents(&components); |
48 return FilePath(components[0]); | 48 return FilePath(components[0]); |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
| 53 // TODO(kinuko): we should have separate tests for DraggedFileUtil and |
| 54 // IsolatedFileUtil. |
53 class IsolatedFileUtilTest : public testing::Test { | 55 class IsolatedFileUtilTest : public testing::Test { |
54 public: | 56 public: |
55 IsolatedFileUtilTest() {} | 57 IsolatedFileUtilTest() {} |
56 | 58 |
57 void SetUp() { | 59 void SetUp() { |
58 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 60 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
59 file_util_.reset(new IsolatedFileUtil()); | 61 file_util_.reset(new DraggedFileUtil()); |
60 | 62 |
61 // Register the files/directories of RegularTestCases (with random | 63 // Register the files/directories of RegularTestCases (with random |
62 // root paths) as dropped files. | 64 // root paths) as dropped files. |
63 SimulateDropFiles(); | 65 SimulateDropFiles(); |
64 | 66 |
65 file_system_context_ = new FileSystemContext( | 67 file_system_context_ = new FileSystemContext( |
66 base::MessageLoopProxy::current(), | 68 base::MessageLoopProxy::current(), |
67 base::MessageLoopProxy::current(), | 69 base::MessageLoopProxy::current(), |
68 make_scoped_refptr(new quota::MockSpecialStoragePolicy()), | 70 make_scoped_refptr(new quota::MockSpecialStoragePolicy()), |
69 NULL /* quota_manager */, | 71 NULL /* quota_manager */, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 201 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
200 FilePath path(test_case.path); | 202 FilePath path(test_case.path); |
201 FilePath toplevel = GetTopLevelPath(path); | 203 FilePath toplevel = GetTopLevelPath(path); |
202 | 204 |
203 // We create the test case files under one of the kRootPaths | 205 // We create the test case files under one of the kRootPaths |
204 // to simulate a drop with multiple directories. | 206 // to simulate a drop with multiple directories. |
205 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { | 207 if (toplevel_root_map_.find(toplevel) == toplevel_root_map_.end()) { |
206 FilePath root = root_path().Append( | 208 FilePath root = root_path().Append( |
207 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); | 209 kRootPaths[(root_path_index++) % arraysize(kRootPaths)]); |
208 toplevel_root_map_[toplevel] = root; | 210 toplevel_root_map_[toplevel] = root; |
209 toplevels.AddPath(root.Append(path)); | 211 toplevels.AddPath(root.Append(path), NULL); |
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()->RegisterFileSystem(toplevels); | 218 filesystem_id_ = isolated_context()->RegisterDraggedFileSystem(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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 false /* exclusive */, | 389 false /* exclusive */, |
388 true /* recursive */)); | 390 true /* recursive */)); |
389 | 391 |
390 context.reset(new FileSystemOperationContext(file_system_context())); | 392 context.reset(new FileSystemOperationContext(file_system_context())); |
391 ASSERT_EQ(base::PLATFORM_FILE_OK, | 393 ASSERT_EQ(base::PLATFORM_FILE_OK, |
392 FileUtilHelper::Copy( | 394 FileUtilHelper::Copy( |
393 context.get(), | 395 context.get(), |
394 file_util(), other_file_util(), | 396 file_util(), other_file_util(), |
395 src_url, dest_url)); | 397 src_url, dest_url)); |
396 | 398 |
397 // The other way (copy-in) should not work. | |
398 context.reset(new FileSystemOperationContext(file_system_context())); | |
399 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, | |
400 FileUtilHelper::Copy( | |
401 context.get(), | |
402 other_file_util(), file_util(), | |
403 dest_url, src_url)); | |
404 | |
405 VerifyFilesHaveSameContent(file_util(), other_file_util(), | 399 VerifyFilesHaveSameContent(file_util(), other_file_util(), |
406 src_url, dest_url); | 400 src_url, dest_url); |
407 } | 401 } |
408 } | 402 } |
409 | 403 |
410 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { | 404 TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { |
411 scoped_ptr<FileSystemOperationContext> context( | 405 scoped_ptr<FileSystemOperationContext> context( |
412 new FileSystemOperationContext(file_system_context())); | 406 new FileSystemOperationContext(file_system_context())); |
413 FileSystemURL root_url = GetFileSystemURL(FilePath()); | 407 FileSystemURL root_url = GetFileSystemURL(FilePath()); |
414 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | 408 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
(...skipping 20 matching lines...) Expand all Loading... |
435 false /* exclusive */, | 429 false /* exclusive */, |
436 true /* recursive */)); | 430 true /* recursive */)); |
437 | 431 |
438 context.reset(new FileSystemOperationContext(file_system_context())); | 432 context.reset(new FileSystemOperationContext(file_system_context())); |
439 ASSERT_EQ(base::PLATFORM_FILE_OK, | 433 ASSERT_EQ(base::PLATFORM_FILE_OK, |
440 FileUtilHelper::Copy( | 434 FileUtilHelper::Copy( |
441 context.get(), | 435 context.get(), |
442 file_util(), other_file_util(), | 436 file_util(), other_file_util(), |
443 src_url, dest_url)); | 437 src_url, dest_url)); |
444 | 438 |
445 // The other way (copy-in) should not work for two reasons: | |
446 // write is prohibited in the isolated filesystem, and copying directory | |
447 // to non-empty directory shouldn't work. | |
448 context.reset(new FileSystemOperationContext(file_system_context())); | |
449 base::PlatformFileError result = FileUtilHelper::Copy( | |
450 context.get(), other_file_util(), file_util(), dest_url, src_url); | |
451 ASSERT_TRUE(result == base::PLATFORM_FILE_ERROR_FAILED || | |
452 result == base::PLATFORM_FILE_ERROR_NOT_EMPTY); | |
453 | |
454 VerifyDirectoriesHaveSameContent(file_util(), other_file_util(), | 439 VerifyDirectoriesHaveSameContent(file_util(), other_file_util(), |
455 src_url, dest_url); | 440 src_url, dest_url); |
456 } | 441 } |
457 } | 442 } |
458 | 443 |
459 TEST_F(IsolatedFileUtilTest, TouchTest) { | 444 TEST_F(IsolatedFileUtilTest, TouchTest) { |
460 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { | 445 for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { |
461 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; | 446 const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; |
462 if (test_case.is_directory) | 447 if (test_case.is_directory) |
463 continue; | 448 continue; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 EXPECT_EQ(base::PLATFORM_FILE_OK, | 491 EXPECT_EQ(base::PLATFORM_FILE_OK, |
507 file_util()->Truncate(GetOperationContext().get(), url, 999)); | 492 file_util()->Truncate(GetOperationContext().get(), url, 999)); |
508 ASSERT_EQ(base::PLATFORM_FILE_OK, | 493 ASSERT_EQ(base::PLATFORM_FILE_OK, |
509 file_util()->GetFileInfo(GetOperationContext().get(), url, | 494 file_util()->GetFileInfo(GetOperationContext().get(), url, |
510 &info, &platform_path)); | 495 &info, &platform_path)); |
511 EXPECT_EQ(999, info.size); | 496 EXPECT_EQ(999, info.size); |
512 } | 497 } |
513 } | 498 } |
514 | 499 |
515 } // namespace fileapi | 500 } // namespace fileapi |
OLD | NEW |