1 // Copyright 2014 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. 4 5 #include "content/test/fileapi_test_file_set.h" 6 7 #include <string> 8 9 #include "base/file_util.h" 10 #include "base/files/file.h" 11 #include "base/logging.h" 12 #include "base/rand_util.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 namespace content { 16 17 const FileSystemTestCaseRecord kRegularFileSystemTestCases[] = { 18 {true, FILE_PATH_LITERAL("dir a"), 0}, 19 {true, FILE_PATH_LITERAL("dir a/dir A"), 0}, 20 {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, 21 {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, 22 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir f"), 0}, 23 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g"), 0}, 24 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0}, 25 {true, FILE_PATH_LITERAL("dir b"), 0}, 26 {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, 27 {true, FILE_PATH_LITERAL("dir c"), 0}, 28 {false, FILE_PATH_LITERAL("file 0"), 38}, 29 {false, FILE_PATH_LITERAL("file 2"), 60}, 30 {false, FILE_PATH_LITERAL("file 3"), 0}, 31 {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, 32 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 0"), 40}, 33 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 1"), 41}, 34 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 2"), 42}, 35 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50}, 36 }; 37 38 const size_t kRegularFileSystemTestCaseSize = 39 arraysize(kRegularFileSystemTestCases); 40 41 void SetUpOneFileSystemTestCase(const base::FilePath& root_path, 42 const FileSystemTestCaseRecord& test_case) { 43 base::FilePath path = root_path.Append(test_case.path); 44 if (test_case.is_directory) { 45 ASSERT_TRUE(base::CreateDirectory(path)); 46 return; 47 } 48 base::File file(path, 49 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); 50 ASSERT_TRUE(file.IsValid()); 51 if (test_case.data_file_size) { 52 std::string content = base::RandBytesAsString(test_case.data_file_size); 53 EXPECT_LE(test_case.data_file_size, kint32max); 54 ASSERT_EQ(static_cast<int>(content.size()), 55 file.Write(0, content.data(), static_cast<int>(content.size()))); 56 } 57 } 58 59 60 void SetUpRegularFileSystemTestCases(const base::FilePath& root_path) { 61 for (size_t i = 0; i < arraysize(kRegularFileSystemTestCases); ++i) { 62 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i); 63 SetUpOneFileSystemTestCase(root_path, kRegularFileSystemTestCases[i]); 64 } 65 } 66 67 } // namespace content 68