Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 // FileSystem. | 32 // FileSystem. |
| 33 class FileSystemOperationTest : public testing::Test { | 33 class FileSystemOperationTest : public testing::Test { |
| 34 public: | 34 public: |
| 35 FileSystemOperationTest() | 35 FileSystemOperationTest() |
| 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_local_path(const FilePath& path) { local_path_ = path; } | |
| 43 const FilePath& local_path() const { return local_path_; } | |
| 42 void set_status(int status) { status_ = status; } | 44 void set_status(int status) { status_ = status; } |
| 43 int status() const { return status_; } | 45 int status() const { return status_; } |
| 44 void set_info(const base::PlatformFileInfo& info) { info_ = info; } | 46 void set_info(const base::PlatformFileInfo& info) { info_ = info; } |
| 45 const base::PlatformFileInfo& info() const { return info_; } | 47 const base::PlatformFileInfo& info() const { return info_; } |
| 46 void set_path(const FilePath& path) { path_ = path; } | 48 void set_path(const FilePath& path) { path_ = path; } |
| 47 const FilePath& path() const { return path_; } | 49 const FilePath& path() const { return path_; } |
| 48 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { | 50 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) { |
| 49 entries_ = entries; | 51 entries_ = entries; |
| 50 } | 52 } |
| 51 const std::vector<base::FileUtilProxy::Entry>& entries() const { | 53 const std::vector<base::FileUtilProxy::Entry>& entries() const { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 63 | 65 |
| 64 GURL URLForPath(const FilePath& path) const { | 66 GURL URLForPath(const FilePath& path) const { |
| 65 // Only the path will actually get used. | 67 // Only the path will actually get used. |
| 66 return GURL("file://").Resolve(path.value()); | 68 return GURL("file://").Resolve(path.value()); |
| 67 } | 69 } |
| 68 | 70 |
| 69 // For post-operation status. | 71 // For post-operation status. |
| 70 int status_; | 72 int status_; |
| 71 base::PlatformFileInfo info_; | 73 base::PlatformFileInfo info_; |
| 72 FilePath path_; | 74 FilePath path_; |
| 75 FilePath local_path_; | |
| 73 std::vector<base::FileUtilProxy::Entry> entries_; | 76 std::vector<base::FileUtilProxy::Entry> entries_; |
| 74 | 77 |
| 75 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); | 78 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 class MockDispatcher : public FileSystemCallbackDispatcher { | 81 class MockDispatcher : public FileSystemCallbackDispatcher { |
| 79 public: | 82 public: |
| 80 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } | 83 MockDispatcher(FileSystemOperationTest* test) : test_(test) { } |
| 81 | 84 |
| 82 virtual void DidFail(base::PlatformFileError status) { | 85 virtual void DidFail(base::PlatformFileError status) { |
| 83 test_->set_status(status); | 86 test_->set_status(status); |
| 84 } | 87 } |
| 85 | 88 |
| 86 virtual void DidSucceed() { | 89 virtual void DidSucceed() { |
| 87 test_->set_status(kFileOperationSucceeded); | 90 test_->set_status(kFileOperationSucceeded); |
| 88 } | 91 } |
| 89 | 92 |
| 93 virtual void DidGetLocalPath(const FilePath& local_path) { | |
| 94 test_->set_local_path(local_path); | |
| 95 } | |
| 96 | |
| 90 virtual void DidReadMetadata( | 97 virtual void DidReadMetadata( |
| 91 const base::PlatformFileInfo& info, | 98 const base::PlatformFileInfo& info, |
| 92 const FilePath& platform_path) { | 99 const FilePath& platform_path) { |
| 93 test_->set_info(info); | 100 test_->set_info(info); |
| 94 test_->set_path(platform_path); | 101 test_->set_path(platform_path); |
| 95 test_->set_status(kFileOperationSucceeded); | 102 test_->set_status(kFileOperationSucceeded); |
| 96 } | 103 } |
| 97 | 104 |
| 98 virtual void DidReadDirectory( | 105 virtual void DidReadDirectory( |
| 99 const std::vector<base::FileUtilProxy::Entry>& entries, | 106 const std::vector<base::FileUtilProxy::Entry>& entries, |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); | 731 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); |
| 725 FilePath child_dir; | 732 FilePath child_dir; |
| 726 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( | 733 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( |
| 727 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); | 734 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); |
| 728 | 735 |
| 729 operation()->Remove(URLForPath(parent_dir.path()), true /* recursive */); | 736 operation()->Remove(URLForPath(parent_dir.path()), true /* recursive */); |
| 730 MessageLoop::current()->RunAllPending(); | 737 MessageLoop::current()->RunAllPending(); |
| 731 EXPECT_EQ(kFileOperationSucceeded, status()); | 738 EXPECT_EQ(kFileOperationSucceeded, status()); |
| 732 EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path())); | 739 EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path())); |
| 733 } | 740 } |
| 734 | 741 |
|
ericu
2011/04/19 20:30:49
Missing test for new operation.
zel
2011/04/20 02:02:07
Tests added. Done.
| |
| 735 TEST_F(FileSystemOperationTest, TestTruncate) { | 742 TEST_F(FileSystemOperationTest, TestTruncate) { |
| 736 ScopedTempDir dir; | 743 ScopedTempDir dir; |
| 737 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 744 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 738 FilePath file; | 745 FilePath file; |
| 739 file_util::CreateTemporaryFileInDir(dir.path(), &file); | 746 file_util::CreateTemporaryFileInDir(dir.path(), &file); |
| 740 | 747 |
| 741 char test_data[] = "test data"; | 748 char test_data[] = "test data"; |
| 742 int data_size = static_cast<int>(sizeof(test_data)); | 749 int data_size = static_cast<int>(sizeof(test_data)); |
| 743 EXPECT_EQ(data_size, | 750 EXPECT_EQ(data_size, |
| 744 file_util::WriteFile(file, test_data, data_size)); | 751 file_util::WriteFile(file, test_data, data_size)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 | 786 |
| 780 // Check that its length is now 3 and that it contains only bits of test data. | 787 // Check that its length is now 3 and that it contains only bits of test data. |
| 781 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); | 788 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); |
| 782 EXPECT_EQ(length, info.size); | 789 EXPECT_EQ(length, info.size); |
| 783 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); | 790 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); |
| 784 for (int i = 0; i < length; ++i) | 791 for (int i = 0; i < length; ++i) |
| 785 EXPECT_EQ(test_data[i], data[i]); | 792 EXPECT_EQ(test_data[i], data[i]); |
| 786 } | 793 } |
| 787 | 794 |
| 788 } // namespace fileapi | 795 } // namespace fileapi |
| OLD | NEW |