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

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

Issue 206783004: Remove PlatforFile from fileapi/native_file_util (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change API to return File Created 6 years, 9 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 <set> 5 #include <set>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
10 #include "base/platform_file.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/browser/fileapi/native_file_util.h" 12 #include "webkit/browser/fileapi/native_file_util.h"
13 13
14 namespace fileapi { 14 namespace fileapi {
15 15
16 class NativeFileUtilTest : public testing::Test { 16 class NativeFileUtilTest : public testing::Test {
17 public: 17 public:
18 NativeFileUtilTest() {} 18 NativeFileUtilTest() {}
19 19
20 virtual void SetUp() { 20 virtual void SetUp() {
(...skipping 21 matching lines...) Expand all
42 } 42 }
43 43
44 private: 44 private:
45 base::ScopedTempDir data_dir_; 45 base::ScopedTempDir data_dir_;
46 46
47 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); 47 DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest);
48 }; 48 };
49 49
50 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) { 50 TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) {
51 base::FilePath file_name = Path("test_file"); 51 base::FilePath file_name = Path("test_file");
52 base::PlatformFile file_handle; 52 int flags = base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
53 bool created = false; 53 base::File file =
54 int flags = base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC; 54 NativeFileUtil::CreateOrOpen(file_name, base::File::FLAG_CREATE | flags);
55 ASSERT_EQ(base::File::FILE_OK, 55 ASSERT_TRUE(file.IsValid());
56 NativeFileUtil::CreateOrOpen(file_name, 56 ASSERT_TRUE(file.created());
57 base::PLATFORM_FILE_CREATE | flags,
58 &file_handle, &created));
59 ASSERT_TRUE(created);
60 57
61 EXPECT_TRUE(base::PathExists(file_name)); 58 EXPECT_TRUE(base::PathExists(file_name));
62 EXPECT_TRUE(NativeFileUtil::PathExists(file_name)); 59 EXPECT_TRUE(NativeFileUtil::PathExists(file_name));
63 EXPECT_EQ(0, GetSize(file_name)); 60 EXPECT_EQ(0, GetSize(file_name));
64 EXPECT_NE(base::kInvalidPlatformFileValue, file_handle); 61 file.Close();
65 62
66 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Close(file_handle)); 63 file = NativeFileUtil::CreateOrOpen(file_name, base::File::FLAG_OPEN | flags);
67 64 ASSERT_TRUE(file.IsValid());
68 ASSERT_EQ(base::File::FILE_OK, 65 ASSERT_FALSE(file.created());
69 NativeFileUtil::CreateOrOpen(file_name, 66 file.Close();
70 base::PLATFORM_FILE_OPEN | flags,
71 &file_handle, &created));
72 ASSERT_FALSE(created);
73 ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::Close(file_handle));
74 67
75 ASSERT_EQ(base::File::FILE_OK, 68 ASSERT_EQ(base::File::FILE_OK,
76 NativeFileUtil::DeleteFile(file_name)); 69 NativeFileUtil::DeleteFile(file_name));
77 EXPECT_FALSE(base::PathExists(file_name)); 70 EXPECT_FALSE(base::PathExists(file_name));
78 EXPECT_FALSE(NativeFileUtil::PathExists(file_name)); 71 EXPECT_FALSE(NativeFileUtil::PathExists(file_name));
79 } 72 }
80 73
81 TEST_F(NativeFileUtilTest, EnsureFileExists) { 74 TEST_F(NativeFileUtilTest, EnsureFileExists) {
82 base::FilePath file_name = Path("foobar"); 75 base::FilePath file_name = Path("foobar");
83 bool created = false; 76 bool created = false;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, 396 FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
404 NativeFileUtil::MOVE)); 397 NativeFileUtil::MOVE));
405 398
406 ASSERT_TRUE(FileExists(to_file3)); 399 ASSERT_TRUE(FileExists(to_file3));
407 ASSERT_EQ(base::File::FILE_OK, 400 ASSERT_EQ(base::File::FILE_OK,
408 NativeFileUtil::GetFileInfo(to_file2, &file_info2)); 401 NativeFileUtil::GetFileInfo(to_file2, &file_info2));
409 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified); 402 EXPECT_EQ(file_info1.last_modified, file_info2.last_modified);
410 } 403 }
411 404
412 } // namespace fileapi 405 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698