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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/browser/fileapi/native_file_util.h" 10 #include "webkit/browser/fileapi/native_file_util.h"
(...skipping 11 matching lines...) Expand all
22 protected: 22 protected:
23 base::FilePath Path() { 23 base::FilePath Path() {
24 return data_dir_.path(); 24 return data_dir_.path();
25 } 25 }
26 26
27 base::FilePath Path(const char* file_name) { 27 base::FilePath Path(const char* file_name) {
28 return data_dir_.path().AppendASCII(file_name); 28 return data_dir_.path().AppendASCII(file_name);
29 } 29 }
30 30
31 bool FileExists(const base::FilePath& path) { 31 bool FileExists(const base::FilePath& path) {
32 return file_util::PathExists(path) && 32 return base::PathExists(path) &&
33 !file_util::DirectoryExists(path); 33 !file_util::DirectoryExists(path);
34 } 34 }
35 35
36 int64 GetSize(const base::FilePath& path) { 36 int64 GetSize(const base::FilePath& path) {
37 base::PlatformFileInfo info; 37 base::PlatformFileInfo info;
38 file_util::GetFileInfo(path, &info); 38 file_util::GetFileInfo(path, &info);
39 return info.size; 39 return info.size;
40 } 40 }
41 41
42 private: 42 private:
43 base::ScopedTempDir data_dir_; 43 base::ScopedTempDir data_dir_;
44 44
45 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); 45 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest);
46 }; 46 };
47 47
48 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) { 48 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) {
49 base::FilePath file_name = Path("test_file"); 49 base::FilePath file_name = Path("test_file");
50 base::PlatformFile file_handle; 50 base::PlatformFile file_handle;
51 bool created = false; 51 bool created = false;
52 int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 52 int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
53 ASSERT_EQ(base::PLATFORM_FILE_OK, 53 ASSERT_EQ(base::PLATFORM_FILE_OK,
54 NativeFileUtil::CreateOrOpen(file_name, 54 NativeFileUtil::CreateOrOpen(file_name,
55 base::PLATFORM_FILE_CREATE | flags, 55 base::PLATFORM_FILE_CREATE | flags,
56 &file_handle, &created)); 56 &file_handle, &created));
57 ASSERT_TRUE(created); 57 ASSERT_TRUE(created);
58 58
59 EXPECT_TRUE(file_util::PathExists(file_name)); 59 EXPECT_TRUE(base::PathExists(file_name));
60 EXPECT_TRUE(NativeFileUtil::PathExists(file_name)); 60 EXPECT_TRUE(NativeFileUtil::PathExists(file_name));
61 EXPECT_EQ(0, GetSize(file_name)); 61 EXPECT_EQ(0, GetSize(file_name));
62 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 62 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle);
63 63
64 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle)); 64 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle));
65 65
66 ASSERT_EQ(base::PLATFORM_FILE_OK, 66 ASSERT_EQ(base::PLATFORM_FILE_OK,
67 NativeFileUtil::CreateOrOpen(file_name, 67 NativeFileUtil::CreateOrOpen(file_name,
68 base::PLATFORM_FILE_OPEN | flags, 68 base::PLATFORM_FILE_OPEN | flags,
69 &file_handle, &created)); 69 &file_handle, &created));
70 ASSERT_FALSE(created); 70 ASSERT_FALSE(created);
71 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle)); 71 ASSERT_EQ(base::PLATFORM_FILE_OK, NativeFileUtil::Close(file_handle));
72 72
73 ASSERT_EQ(base::PLATFORM_FILE_OK, 73 ASSERT_EQ(base::PLATFORM_FILE_OK,
74 NativeFileUtil::DeleteFile(file_name)); 74 NativeFileUtil::DeleteFile(file_name));
75 EXPECT_FALSE(file_util::PathExists(file_name)); 75 EXPECT_FALSE(base::PathExists(file_name));
76 EXPECT_FALSE(NativeFileUtil::PathExists(file_name)); 76 EXPECT_FALSE(NativeFileUtil::PathExists(file_name));
77 } 77 }
78 78
79 TEST_F(NativeFileUtilTest, EnsureFileExists) { 79 TEST_F(NativeFileUtilTest, EnsureFileExists) {
80 base::FilePath file_name = Path("foobar"); 80 base::FilePath file_name = Path("foobar");
81 bool created = false; 81 bool created = false;
82 ASSERT_EQ(base::PLATFORM_FILE_OK, 82 ASSERT_EQ(base::PLATFORM_FILE_OK,
83 NativeFileUtil::EnsureFileExists(file_name, &created)); 83 NativeFileUtil::EnsureFileExists(file_name, &created));
84 ASSERT_TRUE(created); 84 ASSERT_TRUE(created);
85 85
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 Path("nodir").AppendASCII("file"), 332 Path("nodir").AppendASCII("file"),
333 false)); 333 false));
334 // Destination's parent is a file. 334 // Destination's parent is a file.
335 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, 335 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
336 NativeFileUtil::CopyOrMoveFile(from_file, 336 NativeFileUtil::CopyOrMoveFile(from_file,
337 Path("tofile1").AppendASCII("file"), 337 Path("tofile1").AppendASCII("file"),
338 false)); 338 false));
339 } 339 }
340 340
341 } // namespace fileapi 341 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/native_file_util.cc ('k') | webkit/browser/fileapi/obfuscated_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698