Only sync parent directory once after a leveldb file rename.
[chromium-blink-merge.git] / webkit / fileapi / test_file_set.cc
blob96213f1ee4128fd7a614ba03feeb3d53c5a1a5b9
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
3 // found in the LICENSE file.
5 #include "webkit/fileapi/test_file_set.h"
7 #include <string>
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/platform_file.h"
12 #include "base/rand_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace fileapi {
17 namespace test {
19 const TestCaseRecord kRegularTestCases[] = {
20 {true, FILE_PATH_LITERAL("dir a"), 0},
21 {true, FILE_PATH_LITERAL("dir a/dir A"), 0},
22 {true, FILE_PATH_LITERAL("dir a/dir d"), 0},
23 {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0},
24 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0},
25 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0},
26 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0},
27 {true, FILE_PATH_LITERAL("dir b"), 0},
28 {true, FILE_PATH_LITERAL("dir b/dir a"), 0},
29 {true, FILE_PATH_LITERAL("dir c"), 0},
30 {false, FILE_PATH_LITERAL("file 0"), 38},
31 {false, FILE_PATH_LITERAL("file 2"), 60},
32 {false, FILE_PATH_LITERAL("file 3"), 0},
33 {false, FILE_PATH_LITERAL("dir a/file 0"), 39},
34 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40},
35 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41},
36 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42},
37 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50},
40 const size_t kRegularTestCaseSize = arraysize(kRegularTestCases);
42 void SetUpOneTestCase(const base::FilePath& root_path,
43 const TestCaseRecord& test_case) {
44 base::FilePath path = root_path.Append(test_case.path);
45 if (test_case.is_directory) {
46 ASSERT_TRUE(file_util::CreateDirectory(path));
47 return;
49 base::PlatformFileError error_code;
50 bool created = false;
51 int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS |
52 base::PLATFORM_FILE_WRITE;
53 base::PlatformFile file_handle =
54 base::CreatePlatformFile(path, file_flags, &created, &error_code);
55 EXPECT_TRUE(created);
56 ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
57 ASSERT_NE(base::kInvalidPlatformFileValue, file_handle);
58 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
59 if (test_case.data_file_size > 0U) {
60 std::string content = base::RandBytesAsString(test_case.data_file_size);
61 ASSERT_EQ(static_cast<int>(content.size()),
62 file_util::WriteFile(path, content.data(), content.size()));
67 void SetUpRegularTestCases(const base::FilePath& root_path) {
68 for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) {
69 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i);
70 SetUpOneTestCase(root_path, kRegularTestCases[i]);
74 } // namespace test
76 } // namespace fileapi