diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 10:26:56 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 10:26:56 +0000 |
commit | f83b5b783ac4fd566328772caccb5c3e2d8b8f9a (patch) | |
tree | e098a0aa3aab90d29ab8bacdd8ec4328fa6813c6 /webkit | |
parent | 6e3953dd1dd86347917a18afc83f8c7d1792cd25 (diff) | |
download | chromium_src-f83b5b783ac4fd566328772caccb5c3e2d8b8f9a.zip chromium_src-f83b5b783ac4fd566328772caccb5c3e2d8b8f9a.tar.gz chromium_src-f83b5b783ac4fd566328772caccb5c3e2d8b8f9a.tar.bz2 |
Cleanup: factor out common test sets under fileapi/
I wanted to use the same set of files for other testing and wanted to make this cleanup first.
BUG=none
TEST=existing tests
Review URL: https://chromiumcodereview.appspot.com/9200005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/fileapi/file_system_file_util_unittest.cc | 49 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 59 | ||||
-rw-r--r-- | webkit/fileapi/test_file_set.cc | 69 | ||||
-rw-r--r-- | webkit/fileapi/test_file_set.h | 41 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 2 |
5 files changed, 129 insertions, 91 deletions
diff --git a/webkit/fileapi/file_system_file_util_unittest.cc b/webkit/fileapi/file_system_file_util_unittest.cc index 4095986..e036405 100644 --- a/webkit/fileapi/file_system_file_util_unittest.cc +++ b/webkit/fileapi/file_system_file_util_unittest.cc @@ -13,39 +13,9 @@ #include "webkit/fileapi/file_system_test_helper.h" #include "webkit/fileapi/native_file_util.h" #include "webkit/fileapi/obfuscated_file_util.h" +#include "webkit/fileapi/test_file_set.h" -using namespace fileapi; - -namespace { - -struct CopyMoveTestCaseRecord { - bool is_directory; - const FilePath::CharType path[64]; - int64 data_file_size; -}; - -const CopyMoveTestCaseRecord kCopyMoveTestCases[] = { - {true, FILE_PATH_LITERAL("dir a"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir a"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0}, - {true, FILE_PATH_LITERAL("dir b"), 0}, - {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, - {true, FILE_PATH_LITERAL("dir c"), 0}, - {false, FILE_PATH_LITERAL("file 0"), 38}, - {false, FILE_PATH_LITERAL("file 2"), 60}, - {false, FILE_PATH_LITERAL("file 3"), 0}, - {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, -}; - -} // namespace (anonymous) +namespace fileapi { // This is not yet a full unit test for FileSystemFileUtil. TODO(ericu): Adapt // the other subclasses' unit tests, as mentioned in the comments in @@ -91,8 +61,9 @@ class FileSystemFileUtilTest : public testing::Test { // Set up all the source data. scoped_ptr<FileSystemOperationContext> context; FilePath test_root(FILE_PATH_LITERAL("root directory")); - for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { - const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; + + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath path = test_root.Append(test_case.path); if (test_case.is_directory) { context.reset(NewContext(&src_helper)); @@ -130,8 +101,8 @@ class FileSystemFileUtilTest : public testing::Test { file_util->Move(copy_context.get(), test_root, test_root)); // Validate that the destination paths are correct. - for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { - const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath path = test_root.Append(test_case.path); base::PlatformFileInfo dest_file_info; @@ -154,8 +125,8 @@ class FileSystemFileUtilTest : public testing::Test { // Validate that the source paths are still there [for a copy] or gone [for // a move]. - for (size_t i = 0; i < arraysize(kCopyMoveTestCases); ++i) { - const CopyMoveTestCaseRecord& test_case = kCopyMoveTestCases[i]; + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath path = test_root.Append(test_case.path); base::PlatformFileInfo src_file_info; FilePath data_path; @@ -206,3 +177,5 @@ TEST_F(FileSystemFileUtilTest, TestCrossFileSystemMoveSameOrigin) { TestCrossFileSystemCopyMoveHelper(origin, src_type, origin, dest_type, false); } + +} // namespace fileapi diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index 9d7b380..51e30f6 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -21,6 +21,7 @@ #include "webkit/fileapi/file_system_usage_cache.h" #include "webkit/fileapi/mock_file_system_options.h" #include "webkit/fileapi/obfuscated_file_util.h" +#include "webkit/fileapi/test_file_set.h" #include "webkit/quota/mock_special_storage_policy.h" #include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_types.h" @@ -81,33 +82,6 @@ const CopyMoveTestCaseRecord kCopyMoveTestCases[] = { {false, "dir0/file0", "dir1/file1", true}, }; -struct MigrationTestCaseRecord { - bool is_directory; - const FilePath::CharType path[64]; - int64 data_file_size; -}; - -const MigrationTestCaseRecord kMigrationTestCases[] = { - {true, FILE_PATH_LITERAL("dir a"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir a"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0}, - {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0}, - {true, FILE_PATH_LITERAL("dir b"), 0}, - {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, - {true, FILE_PATH_LITERAL("dir c"), 0}, - {false, FILE_PATH_LITERAL("file 0"), 38}, - {false, FILE_PATH_LITERAL("file 2"), 60}, - {false, FILE_PATH_LITERAL("file 3"), 0}, - {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, - {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, -}; - struct OriginEnumerationTestRecord { std::string origin_url; bool has_temporary; @@ -1215,37 +1189,16 @@ TEST_F(ObfuscatedFileUtilTest, TestMigration) { FilePath root_path = source_dir.path().AppendASCII("chrome-pLmnMWXE7NzTFRsn"); ASSERT_TRUE(file_util::CreateDirectory(root_path)); - for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { - SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); - const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; - FilePath local_src_path = root_path.Append(test_case.path); - if (test_case.is_directory) { - ASSERT_TRUE( - file_util::CreateDirectory(local_src_path)); - } else { - base::PlatformFileError error_code; - bool created = false; - int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; - base::PlatformFile file_handle = - base::CreatePlatformFile( - local_src_path, file_flags, &created, &error_code); - EXPECT_TRUE(created); - ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); - ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); - ASSERT_TRUE( - base::TruncatePlatformFile(file_handle, test_case.data_file_size)); - EXPECT_TRUE(base::ClosePlatformFile(file_handle)); - } - } + test::SetUpRegularTestCases(root_path); EXPECT_TRUE(ofu()->MigrateFromOldSandbox(origin(), type(), root_path)); FilePath new_root = test_directory().AppendASCII("File System").AppendASCII("000").Append( ofu()->GetDirectoryNameForType(type())).AppendASCII("Legacy"); - for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { SCOPED_TRACE(testing::Message() << "Validating kMigrationTestPath " << i); - const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath local_data_path = new_root.Append(test_case.path); #if defined(OS_WIN) local_data_path = local_data_path.NormalizeWindowsPathSeparators(); @@ -1366,9 +1319,9 @@ TEST_F(ObfuscatedFileUtilTest, TestRevokeUsageCache) { int64 expected_quota = 0; - for (size_t i = 0; i < arraysize(kMigrationTestCases); ++i) { + for (size_t i = 0; i < test::kRegularTestCaseSize; ++i) { SCOPED_TRACE(testing::Message() << "Creating kMigrationTestPath " << i); - const MigrationTestCaseRecord& test_case = kMigrationTestCases[i]; + const test::TestCaseRecord& test_case = test::kRegularTestCases[i]; FilePath path(test_case.path); expected_quota += ObfuscatedFileUtil::ComputeFilePathCost(path); if (test_case.is_directory) { diff --git a/webkit/fileapi/test_file_set.cc b/webkit/fileapi/test_file_set.cc new file mode 100644 index 0000000..badb7fb --- /dev/null +++ b/webkit/fileapi/test_file_set.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/fileapi/test_file_set.h" + +#include "base/file_util.h" +#include "base/logging.h" +#include "base/platform_file.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace fileapi { + +namespace test { + +const TestCaseRecord kRegularTestCases[] = { + {true, FILE_PATH_LITERAL("dir a"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir a"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0}, + {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0}, + {true, FILE_PATH_LITERAL("dir b"), 0}, + {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, + {true, FILE_PATH_LITERAL("dir c"), 0}, + {false, FILE_PATH_LITERAL("file 0"), 38}, + {false, FILE_PATH_LITERAL("file 2"), 60}, + {false, FILE_PATH_LITERAL("file 3"), 0}, + {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, + {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, + {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, + {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, + {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, +}; + +const size_t kRegularTestCaseSize = arraysize(kRegularTestCases); + +void SetUpOneTestCase(const FilePath& root_path, + const TestCaseRecord& test_case) { + FilePath path = root_path.Append(test_case.path); + if (test_case.is_directory) { + ASSERT_TRUE(file_util::CreateDirectory(path)); + } else { + base::PlatformFileError error_code; + bool created = false; + int file_flags = base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE; + base::PlatformFile file_handle = + base::CreatePlatformFile(path, file_flags, &created, &error_code); + EXPECT_TRUE(created); + ASSERT_NE(base::kInvalidPlatformFileValue, file_handle); + ASSERT_EQ(base::PLATFORM_FILE_OK, error_code); + ASSERT_TRUE( + base::TruncatePlatformFile(file_handle, test_case.data_file_size)); + EXPECT_TRUE(base::ClosePlatformFile(file_handle)); + } +} + + +void SetUpRegularTestCases(const FilePath& root_path) { + for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) { + SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i); + SetUpOneTestCase(root_path, kRegularTestCases[i]); + } +} + +} // namespace test + +} // namespace fileapi diff --git a/webkit/fileapi/test_file_set.h b/webkit/fileapi/test_file_set.h new file mode 100644 index 0000000..75673c9 --- /dev/null +++ b/webkit/fileapi/test_file_set.h @@ -0,0 +1,41 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_FILEAPI_TEST_FILE_SET_H_ +#define WEBKIT_FILEAPI_TEST_FILE_SET_H_ + +#include <set> + +#include "base/file_path.h" + +// Common test data structures and test cases. + +namespace fileapi { + +class FileSystemFileUtil; + +namespace test { + +struct TestCaseRecord { + bool is_directory; + const FilePath::CharType path[64]; + int64 data_file_size; +}; + +extern const TestCaseRecord kRegularTestCases[]; +extern const size_t kRegularTestCaseSize; + +size_t GetRegularTestCaseSize(); + +// Creates one file or directory specified by |record|. +void SetUpOneTestCase(const FilePath& root_path, const TestCaseRecord& record); + +// Creates the files and directories specified in kRegularTestCases. +void SetUpRegularTestCases(const FilePath& root_path); + +} // namespace test + +} // namespace fileapi + +#endif // WEBKIT_FILEAPI_TEST_FILE_SET_H_ diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 60d1be4..797abec 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -420,6 +420,8 @@ '../../fileapi/obfuscated_file_util_unittest.cc', '../../fileapi/quota_file_util_unittest.cc', '../../fileapi/sandbox_mount_point_provider_unittest.cc', + '../../fileapi/test_file_set.cc', + '../../fileapi/test_file_set.h', '../../fileapi/webfilewriter_base_unittest.cc', '../../glue/bookmarklet_unittest.cc', '../../glue/context_menu_unittest.cc', |