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

Side by Side Diff: webkit/browser/fileapi/test_file_set.cc

Issue 167403002: Remove some PlatformFile uses from WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « webkit/browser/fileapi/sandbox_prioritized_origin_database.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/browser/fileapi/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/logging.h" 11 #include "base/logging.h"
11 #include "base/platform_file.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 fileapi {
16 16
17 namespace test { 17 namespace test {
18 18
19 const TestCaseRecord kRegularTestCases[] = { 19 const TestCaseRecord kRegularTestCases[] = {
20 {true, FILE_PATH_LITERAL("dir a"), 0}, 20 {true, FILE_PATH_LITERAL("dir a"), 0},
21 {true, FILE_PATH_LITERAL("dir a/dir A"), 0}, 21 {true, FILE_PATH_LITERAL("dir a/dir A"), 0},
(...skipping 17 matching lines...) Expand all
39 39
40 const size_t kRegularTestCaseSize = arraysize(kRegularTestCases); 40 const size_t kRegularTestCaseSize = arraysize(kRegularTestCases);
41 41
42 void SetUpOneTestCase(const base::FilePath& root_path, 42 void SetUpOneTestCase(const base::FilePath& root_path,
43 const TestCaseRecord& test_case) { 43 const TestCaseRecord& test_case) {
44 base::FilePath path = root_path.Append(test_case.path); 44 base::FilePath path = root_path.Append(test_case.path);
45 if (test_case.is_directory) { 45 if (test_case.is_directory) {
46 ASSERT_TRUE(base::CreateDirectory(path)); 46 ASSERT_TRUE(base::CreateDirectory(path));
47 return; 47 return;
48 } 48 }
49 base::PlatformFileError error_code; 49 base::File file(path,
50 bool created = false; 50 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
51 int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS | 51 ASSERT_TRUE(file.IsValid());
52 base::PLATFORM_FILE_WRITE; 52 if (test_case.data_file_size) {
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); 53 std::string content = base::RandBytesAsString(test_case.data_file_size);
54 EXPECT_LE(test_case.data_file_size, kint32max);
61 ASSERT_EQ(static_cast<int>(content.size()), 55 ASSERT_EQ(static_cast<int>(content.size()),
62 file_util::WriteFile(path, content.data(), content.size())); 56 file.Write(0, content.data(), static_cast<int>(content.size())));
63 } 57 }
64 } 58 }
65 59
66 60
67 void SetUpRegularTestCases(const base::FilePath& root_path) { 61 void SetUpRegularTestCases(const base::FilePath& root_path) {
68 for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) { 62 for (size_t i = 0; i < arraysize(kRegularTestCases); ++i) {
69 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i); 63 SCOPED_TRACE(testing::Message() << "Creating kRegularTestCases " << i);
70 SetUpOneTestCase(root_path, kRegularTestCases[i]); 64 SetUpOneTestCase(root_path, kRegularTestCases[i]);
71 } 65 }
72 } 66 }
73 67
74 } // namespace test 68 } // namespace test
75 69
76 } // namespace fileapi 70 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/sandbox_prioritized_origin_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698