OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_temp_dir.h" | 9 #include "base/memory/scoped_temp_dir.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 : status_(kFileOperationStatusNotSet) { | 36 : status_(kFileOperationStatusNotSet) { |
37 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 37 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
38 } | 38 } |
39 | 39 |
40 FileSystemOperation* operation(); | 40 FileSystemOperation* operation(); |
41 | 41 |
42 void set_status(int status) { status_ = status; } | 42 void set_status(int status) { status_ = status; } |
43 int status() const { return status_; } | 43 int status() const { return status_; } |
44 void set_info(const base::PlatformFileInfo& info) { info_ = info; } | 44 void set_info(const base::PlatformFileInfo& info) { info_ = info; } |
45 const base::PlatformFileInfo& info() const { return info_; } | 45 const base::PlatformFileInfo& info() const { return info_; } |
| 46 void set_path(const FilePath& path) { path_ = path; } |
| 47 const FilePath& path() const { return path_; } |
46 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { | 48 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { |
47 entries_ = entries; | 49 entries_ = entries; |
48 } | 50 } |
49 const std::vector<base::FileUtilProxy::Entry>& entries() const { | 51 const std::vector<base::FileUtilProxy::Entry>& entries() const { |
50 return entries_; | 52 return entries_; |
51 } | 53 } |
52 | 54 |
53 protected: | 55 protected: |
54 // Common temp base for nondestructive uses. | 56 // Common temp base for nondestructive uses. |
55 ScopedTempDir base_; | 57 ScopedTempDir base_; |
56 | 58 |
57 // For post-operation status. | 59 // For post-operation status. |
58 int status_; | 60 int status_; |
59 base::PlatformFileInfo info_; | 61 base::PlatformFileInfo info_; |
| 62 FilePath path_; |
60 std::vector<base::FileUtilProxy::Entry> entries_; | 63 std::vector<base::FileUtilProxy::Entry> entries_; |
61 | 64 |
62 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 65 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
63 }; | 66 }; |
64 | 67 |
65 class MockDispatcher : public FileSystemCallbackDispatcher { | 68 class MockDispatcher : public FileSystemCallbackDispatcher { |
66 public: | 69 public: |
67 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } | 70 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } |
68 | 71 |
69 virtual void DidFail(base::PlatformFileError status) { | 72 virtual void DidFail(base::PlatformFileError status) { |
70 test_->set_status(status); | 73 test_->set_status(status); |
71 } | 74 } |
72 | 75 |
73 virtual void DidSucceed() { | 76 virtual void DidSucceed() { |
74 test_->set_status(kFileOperationSucceeded); | 77 test_->set_status(kFileOperationSucceeded); |
75 } | 78 } |
76 | 79 |
77 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { | 80 virtual void DidReadMetadata( |
| 81 const base::PlatformFileInfo& info, |
| 82 const FilePath& platform_path) { |
78 test_->set_info(info); | 83 test_->set_info(info); |
| 84 test_->set_path(platform_path); |
79 test_->set_status(kFileOperationSucceeded); | 85 test_->set_status(kFileOperationSucceeded); |
80 } | 86 } |
81 | 87 |
82 virtual void DidReadDirectory( | 88 virtual void DidReadDirectory( |
83 const std::vector<base::FileUtilProxy::Entry>& entries, | 89 const std::vector<base::FileUtilProxy::Entry>& entries, |
84 bool /* has_more */) { | 90 bool /* has_more */) { |
85 test_->set_entries(entries); | 91 test_->set_entries(entries); |
86 } | 92 } |
87 | 93 |
88 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { | 94 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 563 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
558 | 564 |
559 operation()->DirectoryExists(dir.path()); | 565 operation()->DirectoryExists(dir.path()); |
560 MessageLoop::current()->RunAllPending(); | 566 MessageLoop::current()->RunAllPending(); |
561 EXPECT_EQ(kFileOperationSucceeded, status()); | 567 EXPECT_EQ(kFileOperationSucceeded, status()); |
562 | 568 |
563 operation()->GetMetadata(dir.path()); | 569 operation()->GetMetadata(dir.path()); |
564 MessageLoop::current()->RunAllPending(); | 570 MessageLoop::current()->RunAllPending(); |
565 EXPECT_EQ(kFileOperationSucceeded, status()); | 571 EXPECT_EQ(kFileOperationSucceeded, status()); |
566 EXPECT_TRUE(info().is_directory); | 572 EXPECT_TRUE(info().is_directory); |
| 573 EXPECT_EQ(dir.path(), path()); |
567 | 574 |
568 FilePath file; | 575 FilePath file; |
569 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 576 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
570 operation()->FileExists(file); | 577 operation()->FileExists(file); |
571 MessageLoop::current()->RunAllPending(); | 578 MessageLoop::current()->RunAllPending(); |
572 EXPECT_EQ(kFileOperationSucceeded, status()); | 579 EXPECT_EQ(kFileOperationSucceeded, status()); |
573 | 580 |
574 operation()->GetMetadata(file); | 581 operation()->GetMetadata(file); |
575 MessageLoop::current()->RunAllPending(); | 582 MessageLoop::current()->RunAllPending(); |
576 EXPECT_EQ(kFileOperationSucceeded, status()); | 583 EXPECT_EQ(kFileOperationSucceeded, status()); |
577 EXPECT_FALSE(info().is_directory); | 584 EXPECT_FALSE(info().is_directory); |
| 585 EXPECT_EQ(file, path()); |
578 } | 586 } |
579 | 587 |
580 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { | 588 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { |
581 ScopedTempDir dir; | 589 ScopedTempDir dir; |
582 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 590 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
583 operation()->FileExists(dir.path()); | 591 operation()->FileExists(dir.path()); |
584 MessageLoop::current()->RunAllPending(); | 592 MessageLoop::current()->RunAllPending(); |
585 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 593 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
586 | 594 |
587 FilePath file; | 595 FilePath file; |
588 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file)); | 596 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file)); |
589 operation()->DirectoryExists(file); | 597 operation()->DirectoryExists(file); |
590 MessageLoop::current()->RunAllPending(); | 598 MessageLoop::current()->RunAllPending(); |
591 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 599 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
592 } | 600 } |
593 | 601 |
594 TEST_F(FileSystemOperationTest, TestReadDirFailure) { | 602 TEST_F(FileSystemOperationTest, TestReadDirFailure) { |
595 // Path doesn't exists | 603 // Path doesn't exist |
596 FilePath nonexisting_dir_path(base_.path().Append( | 604 FilePath nonexisting_dir_path(base_.path().Append( |
597 FILE_PATH_LITERAL("NonExistingDir"))); | 605 FILE_PATH_LITERAL("NonExistingDir"))); |
598 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 606 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
599 operation()->ReadDirectory(nonexisting_dir_path); | 607 operation()->ReadDirectory(nonexisting_dir_path); |
600 MessageLoop::current()->RunAllPending(); | 608 MessageLoop::current()->RunAllPending(); |
601 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 609 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
602 | 610 |
603 // File exists. | 611 // File exists. |
604 ScopedTempDir dir; | 612 ScopedTempDir dir; |
605 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 613 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
606 FilePath file; | 614 FilePath file; |
607 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 615 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 | 756 |
749 // Check that its length is now 3 and that it contains only bits of test data. | 757 // Check that its length is now 3 and that it contains only bits of test data. |
750 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); | 758 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); |
751 EXPECT_EQ(length, info.size); | 759 EXPECT_EQ(length, info.size); |
752 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); | 760 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); |
753 for (int i = 0; i < length; ++i) | 761 for (int i = 0; i < length; ++i) |
754 EXPECT_EQ(test_data[i], data[i]); | 762 EXPECT_EQ(test_data[i], data[i]); |
755 } | 763 } |
756 | 764 |
757 } // namespace fileapi | 765 } // namespace fileapi |
OLD | NEW |