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

Side by Side Diff: webkit/browser/fileapi/sandbox_database_test_helper.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
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/sandbox_database_test_helper.h" 5 #include "webkit/browser/fileapi/sandbox_database_test_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file.h"
12 #include "base/files/file_enumerator.h" 13 #include "base/files/file_enumerator.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/common/fileapi/file_system_util.h" 16 #include "webkit/common/fileapi/file_system_util.h"
16 17
17 namespace fileapi { 18 namespace fileapi {
18 19
19 void CorruptDatabase(const base::FilePath& db_path, 20 void CorruptDatabase(const base::FilePath& db_path,
20 leveldb::FileType type, 21 leveldb::FileType type,
21 ptrdiff_t offset, 22 ptrdiff_t offset,
(...skipping 12 matching lines...) Expand all
34 if (file_type == type && 35 if (file_type == type &&
35 (picked_file_number == kuint64max || picked_file_number < number)) { 36 (picked_file_number == kuint64max || picked_file_number < number)) {
36 picked_file_path = file_path; 37 picked_file_path = file_path;
37 picked_file_number = number; 38 picked_file_number = number;
38 } 39 }
39 } 40 }
40 41
41 EXPECT_FALSE(picked_file_path.empty()); 42 EXPECT_FALSE(picked_file_path.empty());
42 EXPECT_NE(kuint64max, picked_file_number); 43 EXPECT_NE(kuint64max, picked_file_number);
43 44
44 bool created = true; 45 base::File file(picked_file_path,
45 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 46 base::File::FLAG_OPEN | base::File::FLAG_READ |
46 base::PlatformFile file = 47 base::File::FLAG_WRITE);
47 CreatePlatformFile(picked_file_path, 48 ASSERT_TRUE(file.IsValid());
48 base::PLATFORM_FILE_OPEN | 49 EXPECT_FALSE(file.created());
49 base::PLATFORM_FILE_READ |
50 base::PLATFORM_FILE_WRITE,
51 &created, &error);
52 EXPECT_EQ(base::PLATFORM_FILE_OK, error);
53 EXPECT_FALSE(created);
54 50
55 base::PlatformFileInfo file_info; 51 base::File::Info file_info;
56 EXPECT_TRUE(base::GetPlatformFileInfo(file, &file_info)); 52 EXPECT_TRUE(file.GetInfo(&file_info));
57 if (offset < 0) 53 if (offset < 0)
58 offset += file_info.size; 54 offset += file_info.size;
59 EXPECT_GE(offset, 0); 55 EXPECT_GE(offset, 0);
60 EXPECT_LE(offset, file_info.size); 56 EXPECT_LE(offset, file_info.size);
61 57
62 size = std::min(size, static_cast<size_t>(file_info.size - offset)); 58 size = std::min(size, static_cast<size_t>(file_info.size - offset));
63 59
64 std::vector<char> buf(size); 60 std::vector<char> buf(size);
65 int read_size = base::ReadPlatformFile(file, offset, 61 int read_size = file.Read(offset, vector_as_array(&buf), buf.size());
66 vector_as_array(&buf), buf.size());
67 EXPECT_LT(0, read_size); 62 EXPECT_LT(0, read_size);
68 EXPECT_GE(buf.size(), static_cast<size_t>(read_size)); 63 EXPECT_GE(buf.size(), static_cast<size_t>(read_size));
69 buf.resize(read_size); 64 buf.resize(read_size);
70 65
71 std::transform(buf.begin(), buf.end(), buf.begin(), 66 std::transform(buf.begin(), buf.end(), buf.begin(),
72 std::logical_not<char>()); 67 std::logical_not<char>());
73 68
74 int written_size = base::WritePlatformFile(file, offset, 69 int written_size = file.Write(offset, vector_as_array(&buf), buf.size());
75 vector_as_array(&buf), buf.size());
76 EXPECT_GT(written_size, 0); 70 EXPECT_GT(written_size, 0);
77 EXPECT_EQ(buf.size(), static_cast<size_t>(written_size)); 71 EXPECT_EQ(buf.size(), static_cast<size_t>(written_size));
78
79 base::ClosePlatformFile(file);
80 } 72 }
81 73
82 void DeleteDatabaseFile(const base::FilePath& db_path, 74 void DeleteDatabaseFile(const base::FilePath& db_path,
83 leveldb::FileType type) { 75 leveldb::FileType type) {
84 base::FileEnumerator file_enum(db_path, false /* not recursive */, 76 base::FileEnumerator file_enum(db_path, false /* not recursive */,
85 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); 77 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES);
86 base::FilePath file_path; 78 base::FilePath file_path;
87 while (!(file_path = file_enum.Next()).empty()) { 79 while (!(file_path = file_enum.Next()).empty()) {
88 uint64 number = kuint64max; 80 uint64 number = kuint64max;
89 leveldb::FileType file_type; 81 leveldb::FileType file_type;
90 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()), 82 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()),
91 &number, &file_type)); 83 &number, &file_type));
92 if (file_type == type) { 84 if (file_type == type) {
93 base::DeleteFile(file_path, false); 85 base::DeleteFile(file_path, false);
94 // We may have multiple files for the same type, so don't break here. 86 // We may have multiple files for the same type, so don't break here.
95 } 87 }
96 } 88 }
97 } 89 }
98 90
99 } // namespace fileapi 91 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/database/database_tracker_unittest.cc ('k') | webkit/browser/fileapi/sandbox_origin_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698