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

Side by Side Diff: content/browser/fileapi/sandbox_database_test_helper.cc

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "content/browser/fileapi/sandbox_database_test_helper.h" 5 #include "content/browser/fileapi/sandbox_database_test_helper.h"
6 6
7 #include <stdint.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 #include <functional> 10 #include <functional>
11 #include <limits>
9 #include <vector> 12 #include <vector>
10 13
11 #include "base/files/file.h" 14 #include "base/files/file.h"
12 #include "base/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
13 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
14 #include "storage/common/fileapi/file_system_util.h" 17 #include "storage/common/fileapi/file_system_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
16 19
17 using storage::FilePathToString; 20 using storage::FilePathToString;
18 21
19 namespace content { 22 namespace content {
20 23
21 void CorruptDatabase(const base::FilePath& db_path, 24 void CorruptDatabase(const base::FilePath& db_path,
22 leveldb::FileType type, 25 leveldb::FileType type,
23 ptrdiff_t offset, 26 ptrdiff_t offset,
24 size_t size) { 27 size_t size) {
25 base::FileEnumerator file_enum(db_path, false /* not recursive */, 28 base::FileEnumerator file_enum(db_path, false /* not recursive */,
26 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); 29 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES);
27 base::FilePath file_path; 30 base::FilePath file_path;
28 base::FilePath picked_file_path; 31 base::FilePath picked_file_path;
29 uint64 picked_file_number = kuint64max; 32 uint64_t picked_file_number = std::numeric_limits<uint64_t>::max();
30 33
31 while (!(file_path = file_enum.Next()).empty()) { 34 while (!(file_path = file_enum.Next()).empty()) {
32 uint64 number = kuint64max; 35 uint64_t number = std::numeric_limits<uint64_t>::max();
33 leveldb::FileType file_type; 36 leveldb::FileType file_type;
34 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()), 37 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()),
35 &number, &file_type)); 38 &number, &file_type));
36 if (file_type == type && 39 if (file_type == type &&
37 (picked_file_number == kuint64max || picked_file_number < number)) { 40 (picked_file_number == std::numeric_limits<uint64_t>::max() ||
41 picked_file_number < number)) {
38 picked_file_path = file_path; 42 picked_file_path = file_path;
39 picked_file_number = number; 43 picked_file_number = number;
40 } 44 }
41 } 45 }
42 46
43 EXPECT_FALSE(picked_file_path.empty()); 47 EXPECT_FALSE(picked_file_path.empty());
44 EXPECT_NE(kuint64max, picked_file_number); 48 EXPECT_NE(std::numeric_limits<uint64_t>::max(), picked_file_number);
45 49
46 base::File file(picked_file_path, 50 base::File file(picked_file_path,
47 base::File::FLAG_OPEN | base::File::FLAG_READ | 51 base::File::FLAG_OPEN | base::File::FLAG_READ |
48 base::File::FLAG_WRITE); 52 base::File::FLAG_WRITE);
49 ASSERT_TRUE(file.IsValid()); 53 ASSERT_TRUE(file.IsValid());
50 EXPECT_FALSE(file.created()); 54 EXPECT_FALSE(file.created());
51 55
52 base::File::Info file_info; 56 base::File::Info file_info;
53 EXPECT_TRUE(file.GetInfo(&file_info)); 57 EXPECT_TRUE(file.GetInfo(&file_info));
54 if (offset < 0) 58 if (offset < 0)
(...skipping 16 matching lines...) Expand all
71 EXPECT_GT(written_size, 0); 75 EXPECT_GT(written_size, 0);
72 EXPECT_EQ(buf.size(), static_cast<size_t>(written_size)); 76 EXPECT_EQ(buf.size(), static_cast<size_t>(written_size));
73 } 77 }
74 78
75 void DeleteDatabaseFile(const base::FilePath& db_path, 79 void DeleteDatabaseFile(const base::FilePath& db_path,
76 leveldb::FileType type) { 80 leveldb::FileType type) {
77 base::FileEnumerator file_enum(db_path, false /* not recursive */, 81 base::FileEnumerator file_enum(db_path, false /* not recursive */,
78 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); 82 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES);
79 base::FilePath file_path; 83 base::FilePath file_path;
80 while (!(file_path = file_enum.Next()).empty()) { 84 while (!(file_path = file_enum.Next()).empty()) {
81 uint64 number = kuint64max; 85 uint64_t number = std::numeric_limits<uint64_t>::max();
82 leveldb::FileType file_type; 86 leveldb::FileType file_type;
83 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()), 87 EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()),
84 &number, &file_type)); 88 &number, &file_type));
85 if (file_type == type) { 89 if (file_type == type) {
86 base::DeleteFile(file_path, false); 90 base::DeleteFile(file_path, false);
87 // We may have multiple files for the same type, so don't break here. 91 // We may have multiple files for the same type, so don't break here.
88 } 92 }
89 } 93 }
90 } 94 }
91 95
92 } // namespace content 96 } // namespace content
OLDNEW
« no previous file with comments | « components/storage_monitor/storage_monitor_linux.cc ('k') | content/browser/fileapi/upload_file_system_file_element_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698