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

Side by Side Diff: base/files/file_util_proxy_unittest.cc

Issue 2275553005: //base: Make ScopedTempDir::path() a GetPath() with a DCHECK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 4 years, 3 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
« no previous file with comments | « base/files/file_unittest.cc ('k') | base/files/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/files/file_util_proxy.h" 5 #include "base/files/file_util_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 24 matching lines...) Expand all
35 const File::Info& file_info) { 35 const File::Info& file_info) {
36 error_ = error; 36 error_ = error;
37 file_info_ = file_info; 37 file_info_ = file_info;
38 MessageLoop::current()->QuitWhenIdle(); 38 MessageLoop::current()->QuitWhenIdle();
39 } 39 }
40 40
41 protected: 41 protected:
42 TaskRunner* file_task_runner() const { 42 TaskRunner* file_task_runner() const {
43 return file_thread_.task_runner().get(); 43 return file_thread_.task_runner().get();
44 } 44 }
45 const FilePath& test_dir_path() const { return dir_.path(); } 45 const FilePath TestPath() const { return dir_.GetPath().AppendASCII("test"); }
46 const FilePath test_path() const { return dir_.path().AppendASCII("test"); }
47 46
48 MessageLoopForIO message_loop_; 47 MessageLoopForIO message_loop_;
49 Thread file_thread_; 48 Thread file_thread_;
50 49
51 ScopedTempDir dir_; 50 ScopedTempDir dir_;
52 File::Error error_; 51 File::Error error_;
53 FilePath path_; 52 FilePath path_;
54 File::Info file_info_; 53 File::Info file_info_;
55 std::vector<char> buffer_; 54 std::vector<char> buffer_;
56 WeakPtrFactory<FileUtilProxyTest> weak_factory_; 55 WeakPtrFactory<FileUtilProxyTest> weak_factory_;
57 }; 56 };
58 57
59 58
60 TEST_F(FileUtilProxyTest, GetFileInfo_File) { 59 TEST_F(FileUtilProxyTest, GetFileInfo_File) {
61 // Setup. 60 // Setup.
62 ASSERT_EQ(4, WriteFile(test_path(), "test", 4)); 61 ASSERT_EQ(4, WriteFile(TestPath(), "test", 4));
63 File::Info expected_info; 62 File::Info expected_info;
64 GetFileInfo(test_path(), &expected_info); 63 GetFileInfo(TestPath(), &expected_info);
65 64
66 // Run. 65 // Run.
67 FileUtilProxy::GetFileInfo( 66 FileUtilProxy::GetFileInfo(
68 file_task_runner(), 67 file_task_runner(), TestPath(),
69 test_path(),
70 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 68 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
71 RunLoop().Run(); 69 RunLoop().Run();
72 70
73 // Verify. 71 // Verify.
74 EXPECT_EQ(File::FILE_OK, error_); 72 EXPECT_EQ(File::FILE_OK, error_);
75 EXPECT_EQ(expected_info.size, file_info_.size); 73 EXPECT_EQ(expected_info.size, file_info_.size);
76 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 74 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
77 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 75 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
78 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 76 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
79 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed); 77 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed);
80 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 78 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
81 } 79 }
82 80
83 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) { 81 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) {
84 // Setup. 82 // Setup.
85 ASSERT_TRUE(base::CreateDirectory(test_path())); 83 ASSERT_TRUE(base::CreateDirectory(TestPath()));
86 File::Info expected_info; 84 File::Info expected_info;
87 GetFileInfo(test_path(), &expected_info); 85 GetFileInfo(TestPath(), &expected_info);
88 86
89 // Run. 87 // Run.
90 FileUtilProxy::GetFileInfo( 88 FileUtilProxy::GetFileInfo(
91 file_task_runner(), 89 file_task_runner(), TestPath(),
92 test_path(),
93 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 90 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
94 RunLoop().Run(); 91 RunLoop().Run();
95 92
96 // Verify. 93 // Verify.
97 EXPECT_EQ(File::FILE_OK, error_); 94 EXPECT_EQ(File::FILE_OK, error_);
98 EXPECT_EQ(expected_info.size, file_info_.size); 95 EXPECT_EQ(expected_info.size, file_info_.size);
99 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 96 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
100 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 97 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
101 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 98 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
102 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed); 99 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed);
103 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 100 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
104 } 101 }
105 102
106 TEST_F(FileUtilProxyTest, Touch) { 103 TEST_F(FileUtilProxyTest, Touch) {
107 ASSERT_EQ(4, WriteFile(test_path(), "test", 4)); 104 ASSERT_EQ(4, WriteFile(TestPath(), "test", 4));
108 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345); 105 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345);
109 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765); 106 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765);
110 107
111 FileUtilProxy::Touch( 108 FileUtilProxy::Touch(
112 file_task_runner(), 109 file_task_runner(), TestPath(), last_accessed_time, last_modified_time,
113 test_path(),
114 last_accessed_time,
115 last_modified_time,
116 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 110 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
117 RunLoop().Run(); 111 RunLoop().Run();
118 EXPECT_EQ(File::FILE_OK, error_); 112 EXPECT_EQ(File::FILE_OK, error_);
119 113
120 File::Info info; 114 File::Info info;
121 GetFileInfo(test_path(), &info); 115 GetFileInfo(TestPath(), &info);
122 116
123 // The returned values may only have the seconds precision, so we cast 117 // The returned values may only have the seconds precision, so we cast
124 // the double values to int here. 118 // the double values to int here.
125 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), 119 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()),
126 static_cast<int>(info.last_modified.ToDoubleT())); 120 static_cast<int>(info.last_modified.ToDoubleT()));
127 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), 121 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()),
128 static_cast<int>(info.last_accessed.ToDoubleT())); 122 static_cast<int>(info.last_accessed.ToDoubleT()));
129 } 123 }
130 124
131 } // namespace base 125 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_unittest.cc ('k') | base/files/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698