diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 03:03:57 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 03:03:57 +0000 |
commit | d20277efdc08eab57d0bede7bca5b3c0a40673f3 (patch) | |
tree | 917a09a5d0ce35504b115c991d74f2baacbbe7d2 /webkit/fileapi/isolated_file_util_unittest.cc | |
parent | 1f9d5d0af7b273ed28c9168c8e8796cb72bfd4f0 (diff) | |
download | chromium_src-d20277efdc08eab57d0bede7bca5b3c0a40673f3.zip chromium_src-d20277efdc08eab57d0bede7bca5b3c0a40673f3.tar.gz chromium_src-d20277efdc08eab57d0bede7bca5b3c0a40673f3.tar.bz2 |
Adding truncate and touch for isolated filesystem
BUG=134039,134078
TEST=IsolatedFileUtilTest.*
Review URL: https://chromiumcodereview.appspot.com/10447139
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143868 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/isolated_file_util_unittest.cc')
-rw-r--r-- | webkit/fileapi/isolated_file_util_unittest.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/webkit/fileapi/isolated_file_util_unittest.cc b/webkit/fileapi/isolated_file_util_unittest.cc index 5e61144..29f2cd5 100644 --- a/webkit/fileapi/isolated_file_util_unittest.cc +++ b/webkit/fileapi/isolated_file_util_unittest.cc @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/message_loop_proxy.h" #include "base/scoped_temp_dir.h" +#include "base/time.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_operation_context.h" @@ -183,6 +184,12 @@ class IsolatedFileUtilTest : public testing::Test { } } + scoped_ptr<FileSystemOperationContext> GetOperationContext() { + return make_scoped_ptr( + new FileSystemOperationContext(file_system_context())).Pass(); + } + + private: void SimulateDropFiles() { size_t root_path_index = 0; @@ -448,4 +455,78 @@ TEST_F(IsolatedFileUtilTest, CopyOutDirectoryTest) { } } +TEST_F(IsolatedFileUtilTest, TouchTest) { + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; + if (test_case.is_directory) + continue; + SCOPED_TRACE(testing::Message() << test_case.path); + FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + + base::Time last_access_time = base::Time::FromTimeT(1000); + base::Time last_modified_time = base::Time::FromTimeT(2000); + + // Set the filesystem non-writable and try calling Touch. + ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), false)); + EXPECT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, + file_util()->Touch(GetOperationContext().get(), path, + last_access_time, + last_modified_time)); + + // Set the filesystem writable and try calling Touch. + ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), true)); + EXPECT_EQ(base::PLATFORM_FILE_OK, + file_util()->Touch(GetOperationContext().get(), path, + last_access_time, + last_modified_time)); + + // Verification. + base::PlatformFileInfo info; + FilePath platform_path; + ASSERT_EQ(base::PLATFORM_FILE_OK, + file_util()->GetFileInfo(GetOperationContext().get(), path, + &info, &platform_path)); + EXPECT_EQ(last_access_time.ToTimeT(), info.last_accessed.ToTimeT()); + EXPECT_EQ(last_modified_time.ToTimeT(), info.last_modified.ToTimeT()); + } +} + +TEST_F(IsolatedFileUtilTest, TruncateTest) { + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; + if (test_case.is_directory) + continue; + + SCOPED_TRACE(testing::Message() << test_case.path); + FileSystemPath path = GetFileSystemPath(FilePath(test_case.path)); + + // Set the filesystem non-writable and try calling Truncate. + ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), false)); + EXPECT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, + file_util()->Truncate(GetOperationContext().get(), path, 0)); + + base::PlatformFileInfo info; + FilePath platform_path; + + // Set the filesystem writable. + ASSERT_TRUE(isolated_context()->SetWritable(filesystem_id(), true)); + + // Truncate to 0. + EXPECT_EQ(base::PLATFORM_FILE_OK, + file_util()->Truncate(GetOperationContext().get(), path, 0)); + ASSERT_EQ(base::PLATFORM_FILE_OK, + file_util()->GetFileInfo(GetOperationContext().get(), path, + &info, &platform_path)); + EXPECT_EQ(0, info.size); + + // Truncate (extend) to 999. + EXPECT_EQ(base::PLATFORM_FILE_OK, + file_util()->Truncate(GetOperationContext().get(), path, 999)); + ASSERT_EQ(base::PLATFORM_FILE_OK, + file_util()->GetFileInfo(GetOperationContext().get(), path, + &info, &platform_path)); + EXPECT_EQ(999, info.size); + } +} + } // namespace fileapi |