Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: content/test/test_file_set.cc

Issue 183343002: Move test_file_set to content/test/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/browser/fileapi/test_file_set.h" 5 #include "content/test/test_file_set.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace fileapi { 15 namespace content {
16 16
17 namespace test { 17 const FileSystemTestCaseRecord kRegularFileSystemTestCases[] = {
18
19 const TestCaseRecord kRegularTestCases[] = {
20 {true, FILE_PATH_LITERAL("dir a"), 0}, 18 {true, FILE_PATH_LITERAL("dir a"), 0},
21 {true, FILE_PATH_LITERAL("dir a/dir A"), 0}, 19 {true, FILE_PATH_LITERAL("dir a/dir A"), 0},
22 {true, FILE_PATH_LITERAL("dir a/dir d"), 0}, 20 {true, FILE_PATH_LITERAL("dir a/dir d"), 0},
23 {true, FILE_PATH_LITERAL("dir a/dir d/dir e"), 0}, 21 {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}, 22 {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}, 23 {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}, 24 {true, FILE_PATH_LITERAL("dir a/dir d/dir e/dir h"), 0},
27 {true, FILE_PATH_LITERAL("dir b"), 0}, 25 {true, FILE_PATH_LITERAL("dir b"), 0},
28 {true, FILE_PATH_LITERAL("dir b/dir a"), 0}, 26 {true, FILE_PATH_LITERAL("dir b/dir a"), 0},
29 {true, FILE_PATH_LITERAL("dir c"), 0}, 27 {true, FILE_PATH_LITERAL("dir c"), 0},
30 {false, FILE_PATH_LITERAL("file 0"), 38}, 28 {false, FILE_PATH_LITERAL("file 0"), 38},
31 {false, FILE_PATH_LITERAL("file 2"), 60}, 29 {false, FILE_PATH_LITERAL("file 2"), 60},
32 {false, FILE_PATH_LITERAL("file 3"), 0}, 30 {false, FILE_PATH_LITERAL("file 3"), 0},
33 {false, FILE_PATH_LITERAL("dir a/file 0"), 39}, 31 {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}, 32 {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}, 33 {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}, 34 {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}, 35 {false, FILE_PATH_LITERAL("dir a/dir d/dir e/dir g/file 3"), 50},
38 }; 36 };
39 37
40 const size_t kRegularTestCaseSize = arraysize(kRegularTestCases); 38 const size_t kRegularFileSystemTestCaseSize =
39 arraysize(kRegularFileSystemTestCases);
41 40
42 void SetUpOneTestCase(const base::FilePath& root_path, 41 void SetUpOneFileSystemTestCase(const base::FilePath& root_path,
43 const TestCaseRecord& test_case) { 42 const FileSystemTestCaseRecord& test_case) {
44 base::FilePath path = root_path.Append(test_case.path); 43 base::FilePath path = root_path.Append(test_case.path);
45 if (test_case.is_directory) { 44 if (test_case.is_directory) {
46 ASSERT_TRUE(base::CreateDirectory(path)); 45 ASSERT_TRUE(base::CreateDirectory(path));
47 return; 46 return;
48 } 47 }
49 base::File file(path, 48 base::File file(path,
50 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); 49 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
51 ASSERT_TRUE(file.IsValid()); 50 ASSERT_TRUE(file.IsValid());
52 if (test_case.data_file_size) { 51 if (test_case.data_file_size) {
53 std::string content = base::RandBytesAsString(test_case.data_file_size); 52 std::string content = base::RandBytesAsString(test_case.data_file_size);
54 EXPECT_LE(test_case.data_file_size, kint32max); 53 EXPECT_LE(test_case.data_file_size, kint32max);
55 ASSERT_EQ(static_cast<int>(content.size()), 54 ASSERT_EQ(static_cast<int>(content.size()),
56 file.Write(0, content.data(), static_cast<int>(content.size()))); 55 file.Write(0, content.data(), static_cast<int>(content.size())));
57 } 56 }
58 } 57 }
59 58
60 59
61 void SetUpRegularTestCases(const base::FilePath& root_path) { 60 void SetUpRegularFileSystemTestCases(const base::FilePath& root_path) {
62 for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) { 61 for (size_t i = 0; i < arraysize(kRegularFileSystemTestCases); ++i) {
63 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i); 62 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i);
64 SetUpOneTestCase(root_path, kRegularTestCases[i]); 63 SetUpOneFileSystemTestCase(root_path, kRegularFileSystemTestCases[i]);
65 } 64 }
66 } 65 }
67 66
68 } // namespace test 67 } // namespace content
69
70 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698