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

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

Issue 105293002: Move more file_util functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return base::PathExists(LocalPath(file_name)) && 78 return base::PathExists(LocalPath(file_name)) &&
79 !base::DirectoryExists(LocalPath(file_name)); 79 !base::DirectoryExists(LocalPath(file_name));
80 } 80 }
81 81
82 bool DirectoryExists(const char *file_name) { 82 bool DirectoryExists(const char *file_name) {
83 return base::DirectoryExists(LocalPath(file_name)); 83 return base::DirectoryExists(LocalPath(file_name));
84 } 84 }
85 85
86 int64 GetSize(const char *file_name) { 86 int64 GetSize(const char *file_name) {
87 base::PlatformFileInfo info; 87 base::PlatformFileInfo info;
88 file_util::GetFileInfo(LocalPath(file_name), &info); 88 base::GetFileInfo(LocalPath(file_name), &info);
89 return info.size; 89 return info.size;
90 } 90 }
91 91
92 base::PlatformFileError CreateFile(const char* file_name, 92 base::PlatformFileError CreateFile(const char* file_name,
93 base::PlatformFile* file_handle, 93 base::PlatformFile* file_handle,
94 bool* created) { 94 bool* created) {
95 int file_flags = base::PLATFORM_FILE_CREATE | 95 int file_flags = base::PLATFORM_FILE_CREATE |
96 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 96 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
97 97
98 scoped_ptr<FileSystemOperationContext> context(NewContext()); 98 scoped_ptr<FileSystemOperationContext> context(NewContext());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 const char *file_name = "test_file"; 185 const char *file_name = "test_file";
186 base::PlatformFile file_handle; 186 base::PlatformFile file_handle;
187 bool created; 187 bool created;
188 ASSERT_EQ(base::PLATFORM_FILE_OK, 188 ASSERT_EQ(base::PLATFORM_FILE_OK,
189 CreateFile(file_name, &file_handle, &created)); 189 CreateFile(file_name, &file_handle, &created));
190 ASSERT_TRUE(created); 190 ASSERT_TRUE(created);
191 191
192 scoped_ptr<FileSystemOperationContext> context(NewContext()); 192 scoped_ptr<FileSystemOperationContext> context(NewContext());
193 193
194 base::PlatformFileInfo info; 194 base::PlatformFileInfo info;
195 ASSERT_TRUE(file_util::GetFileInfo(LocalPath(file_name), &info)); 195 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info));
196 const base::Time new_accessed = 196 const base::Time new_accessed =
197 info.last_accessed + base::TimeDelta::FromHours(10); 197 info.last_accessed + base::TimeDelta::FromHours(10);
198 const base::Time new_modified = 198 const base::Time new_modified =
199 info.last_modified + base::TimeDelta::FromHours(5); 199 info.last_modified + base::TimeDelta::FromHours(5);
200 200
201 EXPECT_EQ(base::PLATFORM_FILE_OK, 201 EXPECT_EQ(base::PLATFORM_FILE_OK,
202 file_util()->Touch(context.get(), CreateURL(file_name), 202 file_util()->Touch(context.get(), CreateURL(file_name),
203 new_accessed, new_modified)); 203 new_accessed, new_modified));
204 204
205 ASSERT_TRUE(file_util::GetFileInfo(LocalPath(file_name), &info)); 205 ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info));
206 EXPECT_EQ(new_accessed, info.last_accessed); 206 EXPECT_EQ(new_accessed, info.last_accessed);
207 EXPECT_EQ(new_modified, info.last_modified); 207 EXPECT_EQ(new_modified, info.last_modified);
208 208
209 EXPECT_EQ(base::PLATFORM_FILE_OK, 209 EXPECT_EQ(base::PLATFORM_FILE_OK,
210 file_util()->Close(context.get(), file_handle)); 210 file_util()->Close(context.get(), file_handle));
211 } 211 }
212 212
213 TEST_F(LocalFileUtilTest, TouchDirectory) { 213 TEST_F(LocalFileUtilTest, TouchDirectory) {
214 const char *dir_name = "test_dir"; 214 const char *dir_name = "test_dir";
215 scoped_ptr<FileSystemOperationContext> context(NewContext()); 215 scoped_ptr<FileSystemOperationContext> context(NewContext());
216 ASSERT_EQ(base::PLATFORM_FILE_OK, 216 ASSERT_EQ(base::PLATFORM_FILE_OK,
217 file_util()->CreateDirectory(context.get(), 217 file_util()->CreateDirectory(context.get(),
218 CreateURL(dir_name), 218 CreateURL(dir_name),
219 false /* exclusive */, 219 false /* exclusive */,
220 false /* recursive */)); 220 false /* recursive */));
221 221
222 base::PlatformFileInfo info; 222 base::PlatformFileInfo info;
223 ASSERT_TRUE(file_util::GetFileInfo(LocalPath(dir_name), &info)); 223 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info));
224 const base::Time new_accessed = 224 const base::Time new_accessed =
225 info.last_accessed + base::TimeDelta::FromHours(10); 225 info.last_accessed + base::TimeDelta::FromHours(10);
226 const base::Time new_modified = 226 const base::Time new_modified =
227 info.last_modified + base::TimeDelta::FromHours(5); 227 info.last_modified + base::TimeDelta::FromHours(5);
228 228
229 EXPECT_EQ(base::PLATFORM_FILE_OK, 229 EXPECT_EQ(base::PLATFORM_FILE_OK,
230 file_util()->Touch(context.get(), CreateURL(dir_name), 230 file_util()->Touch(context.get(), CreateURL(dir_name),
231 new_accessed, new_modified)); 231 new_accessed, new_modified));
232 232
233 ASSERT_TRUE(file_util::GetFileInfo(LocalPath(dir_name), &info)); 233 ASSERT_TRUE(base::GetFileInfo(LocalPath(dir_name), &info));
234 EXPECT_EQ(new_accessed, info.last_accessed); 234 EXPECT_EQ(new_accessed, info.last_accessed);
235 EXPECT_EQ(new_modified, info.last_modified); 235 EXPECT_EQ(new_modified, info.last_modified);
236 } 236 }
237 237
238 TEST_F(LocalFileUtilTest, Truncate) { 238 TEST_F(LocalFileUtilTest, Truncate) {
239 const char *file_name = "truncated"; 239 const char *file_name = "truncated";
240 bool created; 240 bool created;
241 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created)); 241 ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
242 ASSERT_TRUE(created); 242 ASSERT_TRUE(created);
243 243
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 CreateURL(from_dir), 379 CreateURL(from_dir),
380 CreateURL(to_dir))); 380 CreateURL(to_dir)));
381 381
382 EXPECT_FALSE(DirectoryExists(from_dir)); 382 EXPECT_FALSE(DirectoryExists(from_dir));
383 EXPECT_TRUE(DirectoryExists(to_dir)); 383 EXPECT_TRUE(DirectoryExists(to_dir));
384 EXPECT_TRUE(FileExists(to_file)); 384 EXPECT_TRUE(FileExists(to_file));
385 EXPECT_EQ(1020, GetSize(to_file)); 385 EXPECT_EQ(1020, GetSize(to_file));
386 } 386 }
387 387
388 } // namespace fileapi 388 } // namespace fileapi
OLDNEW
« no previous file with comments | « content/browser/fileapi/file_system_operation_impl_unittest.cc ('k') | content/browser/indexed_db/indexed_db_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698