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

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

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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) 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 <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace base { 19 namespace base {
20 20
21 class FileUtilProxyTest : public testing::Test { 21 class FileUtilProxyTest : public testing::Test {
22 public: 22 public:
23 FileUtilProxyTest() 23 FileUtilProxyTest()
24 : file_thread_("FileUtilProxyTestFileThread"), 24 : file_thread_("FileUtilProxyTestFileThread"),
25 error_(PLATFORM_FILE_OK), 25 error_(File::FILE_OK),
26 created_(false), 26 created_(false),
27 file_(kInvalidPlatformFileValue), 27 file_(kInvalidPlatformFileValue),
28 bytes_written_(-1), 28 bytes_written_(-1),
29 weak_factory_(this) {} 29 weak_factory_(this) {}
30 30
31 virtual void SetUp() OVERRIDE { 31 virtual void SetUp() OVERRIDE {
32 ASSERT_TRUE(dir_.CreateUniqueTempDir()); 32 ASSERT_TRUE(dir_.CreateUniqueTempDir());
33 ASSERT_TRUE(file_thread_.Start()); 33 ASSERT_TRUE(file_thread_.Start());
34 } 34 }
35 35
36 virtual void TearDown() OVERRIDE { 36 virtual void TearDown() OVERRIDE {
37 if (file_ != kInvalidPlatformFileValue) 37 if (file_ != kInvalidPlatformFileValue)
38 ClosePlatformFile(file_); 38 ClosePlatformFile(file_);
39 } 39 }
40 40
41 void DidFinish(PlatformFileError error) { 41 void DidFinish(File::Error error) {
42 error_ = error; 42 error_ = error;
43 MessageLoop::current()->QuitWhenIdle(); 43 MessageLoop::current()->QuitWhenIdle();
44 } 44 }
45 45
46 void DidCreateOrOpen(PlatformFileError error, 46 void DidCreateOrOpen(File::Error error,
47 PassPlatformFile file, 47 PassPlatformFile file,
48 bool created) { 48 bool created) {
49 error_ = error; 49 error_ = error;
50 file_ = file.ReleaseValue(); 50 file_ = file.ReleaseValue();
51 created_ = created; 51 created_ = created;
52 MessageLoop::current()->QuitWhenIdle(); 52 MessageLoop::current()->QuitWhenIdle();
53 } 53 }
54 54
55 void DidCreateTemporary(PlatformFileError error, 55 void DidCreateTemporary(File::Error error,
56 PassPlatformFile file, 56 PassPlatformFile file,
57 const FilePath& path) { 57 const FilePath& path) {
58 error_ = error; 58 error_ = error;
59 file_ = file.ReleaseValue(); 59 file_ = file.ReleaseValue();
60 path_ = path; 60 path_ = path;
61 MessageLoop::current()->QuitWhenIdle(); 61 MessageLoop::current()->QuitWhenIdle();
62 } 62 }
63 63
64 void DidGetFileInfo(PlatformFileError error, 64 void DidGetFileInfo(File::Error error,
65 const PlatformFileInfo& file_info) { 65 const File::Info& file_info) {
66 error_ = error; 66 error_ = error;
67 file_info_ = file_info; 67 file_info_ = file_info;
68 MessageLoop::current()->QuitWhenIdle(); 68 MessageLoop::current()->QuitWhenIdle();
69 } 69 }
70 70
71 void DidRead(PlatformFileError error, 71 void DidRead(File::Error error,
72 const char* data, 72 const char* data,
73 int bytes_read) { 73 int bytes_read) {
74 error_ = error; 74 error_ = error;
75 buffer_.resize(bytes_read); 75 buffer_.resize(bytes_read);
76 memcpy(&buffer_[0], data, bytes_read); 76 memcpy(&buffer_[0], data, bytes_read);
77 MessageLoop::current()->QuitWhenIdle(); 77 MessageLoop::current()->QuitWhenIdle();
78 } 78 }
79 79
80 void DidWrite(PlatformFileError error, 80 void DidWrite(File::Error error,
81 int bytes_written) { 81 int bytes_written) {
82 error_ = error; 82 error_ = error;
83 bytes_written_ = bytes_written; 83 bytes_written_ = bytes_written;
84 MessageLoop::current()->QuitWhenIdle(); 84 MessageLoop::current()->QuitWhenIdle();
85 } 85 }
86 86
87 protected: 87 protected:
88 PlatformFile GetTestPlatformFile(int flags) { 88 PlatformFile GetTestPlatformFile(int flags) {
89 if (file_ != kInvalidPlatformFileValue) 89 if (file_ != kInvalidPlatformFileValue)
90 return file_; 90 return file_;
91 bool created; 91 bool created;
92 PlatformFileError error; 92 PlatformFileError error;
93 file_ = CreatePlatformFile(test_path(), flags, &created, &error); 93 file_ = CreatePlatformFile(test_path(), flags, &created, &error);
94 EXPECT_EQ(PLATFORM_FILE_OK, error); 94 EXPECT_EQ(PLATFORM_FILE_OK, error);
95 EXPECT_NE(kInvalidPlatformFileValue, file_); 95 EXPECT_NE(kInvalidPlatformFileValue, file_);
96 return file_; 96 return file_;
97 } 97 }
98 98
99 TaskRunner* file_task_runner() const { 99 TaskRunner* file_task_runner() const {
100 return file_thread_.message_loop_proxy().get(); 100 return file_thread_.message_loop_proxy().get();
101 } 101 }
102 const FilePath& test_dir_path() const { return dir_.path(); } 102 const FilePath& test_dir_path() const { return dir_.path(); }
103 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } 103 const FilePath test_path() const { return dir_.path().AppendASCII("test"); }
104 104
105 MessageLoopForIO message_loop_; 105 MessageLoopForIO message_loop_;
106 Thread file_thread_; 106 Thread file_thread_;
107 107
108 ScopedTempDir dir_; 108 ScopedTempDir dir_;
109 PlatformFileError error_; 109 File::Error error_;
110 bool created_; 110 bool created_;
111 PlatformFile file_; 111 PlatformFile file_;
112 FilePath path_; 112 FilePath path_;
113 PlatformFileInfo file_info_; 113 File::Info file_info_;
114 std::vector<char> buffer_; 114 std::vector<char> buffer_;
115 int bytes_written_; 115 int bytes_written_;
116 WeakPtrFactory<FileUtilProxyTest> weak_factory_; 116 WeakPtrFactory<FileUtilProxyTest> weak_factory_;
117 }; 117 };
118 118
119 TEST_F(FileUtilProxyTest, CreateOrOpen_Create) { 119 TEST_F(FileUtilProxyTest, CreateOrOpen_Create) {
120 FileUtilProxy::CreateOrOpen( 120 FileUtilProxy::CreateOrOpen(
121 file_task_runner(), 121 file_task_runner(),
122 test_path(), 122 test_path(),
123 PLATFORM_FILE_CREATE | PLATFORM_FILE_READ, 123 PLATFORM_FILE_CREATE | PLATFORM_FILE_READ,
124 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 124 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
125 MessageLoop::current()->Run(); 125 MessageLoop::current()->Run();
126 126
127 EXPECT_EQ(PLATFORM_FILE_OK, error_); 127 EXPECT_EQ(File::FILE_OK, error_);
128 EXPECT_TRUE(created_); 128 EXPECT_TRUE(created_);
129 EXPECT_NE(kInvalidPlatformFileValue, file_); 129 EXPECT_NE(kInvalidPlatformFileValue, file_);
130 EXPECT_TRUE(PathExists(test_path())); 130 EXPECT_TRUE(PathExists(test_path()));
131 } 131 }
132 132
133 TEST_F(FileUtilProxyTest, CreateOrOpen_Open) { 133 TEST_F(FileUtilProxyTest, CreateOrOpen_Open) {
134 // Creates a file. 134 // Creates a file.
135 file_util::WriteFile(test_path(), NULL, 0); 135 file_util::WriteFile(test_path(), NULL, 0);
136 ASSERT_TRUE(PathExists(test_path())); 136 ASSERT_TRUE(PathExists(test_path()));
137 137
138 // Opens the created file. 138 // Opens the created file.
139 FileUtilProxy::CreateOrOpen( 139 FileUtilProxy::CreateOrOpen(
140 file_task_runner(), 140 file_task_runner(),
141 test_path(), 141 test_path(),
142 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ, 142 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
143 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 143 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
144 MessageLoop::current()->Run(); 144 MessageLoop::current()->Run();
145 145
146 EXPECT_EQ(PLATFORM_FILE_OK, error_); 146 EXPECT_EQ(File::FILE_OK, error_);
147 EXPECT_FALSE(created_); 147 EXPECT_FALSE(created_);
148 EXPECT_NE(kInvalidPlatformFileValue, file_); 148 EXPECT_NE(kInvalidPlatformFileValue, file_);
149 } 149 }
150 150
151 TEST_F(FileUtilProxyTest, CreateOrOpen_OpenNonExistent) { 151 TEST_F(FileUtilProxyTest, CreateOrOpen_OpenNonExistent) {
152 FileUtilProxy::CreateOrOpen( 152 FileUtilProxy::CreateOrOpen(
153 file_task_runner(), 153 file_task_runner(),
154 test_path(), 154 test_path(),
155 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ, 155 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
156 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 156 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
157 MessageLoop::current()->Run(); 157 MessageLoop::current()->Run();
158 EXPECT_EQ(PLATFORM_FILE_ERROR_NOT_FOUND, error_); 158 EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, error_);
159 EXPECT_FALSE(created_); 159 EXPECT_FALSE(created_);
160 EXPECT_EQ(kInvalidPlatformFileValue, file_); 160 EXPECT_EQ(kInvalidPlatformFileValue, file_);
161 EXPECT_FALSE(PathExists(test_path())); 161 EXPECT_FALSE(PathExists(test_path()));
162 } 162 }
163 163
164 TEST_F(FileUtilProxyTest, Close) { 164 TEST_F(FileUtilProxyTest, Close) {
165 // Creates a file. 165 // Creates a file.
166 PlatformFile file = GetTestPlatformFile( 166 PlatformFile file = GetTestPlatformFile(
167 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE); 167 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE);
168 168
169 #if defined(OS_WIN) 169 #if defined(OS_WIN)
170 // This fails on Windows if the file is not closed. 170 // This fails on Windows if the file is not closed.
171 EXPECT_FALSE(base::Move(test_path(), 171 EXPECT_FALSE(base::Move(test_path(),
172 test_dir_path().AppendASCII("new"))); 172 test_dir_path().AppendASCII("new")));
173 #endif 173 #endif
174 174
175 FileUtilProxy::Close( 175 FileUtilProxy::Close(
176 file_task_runner(), 176 file_task_runner(),
177 file, 177 file,
178 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 178 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
179 MessageLoop::current()->Run(); 179 MessageLoop::current()->Run();
180 EXPECT_EQ(PLATFORM_FILE_OK, error_); 180 EXPECT_EQ(File::FILE_OK, error_);
181 181
182 // Now it should pass on all platforms. 182 // Now it should pass on all platforms.
183 EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new"))); 183 EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new")));
184 } 184 }
185 185
186 TEST_F(FileUtilProxyTest, CreateTemporary) { 186 TEST_F(FileUtilProxyTest, CreateTemporary) {
187 FileUtilProxy::CreateTemporary( 187 FileUtilProxy::CreateTemporary(
188 file_task_runner(), 0 /* additional_file_flags */, 188 file_task_runner(), 0 /* additional_file_flags */,
189 Bind(&FileUtilProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr())); 189 Bind(&FileUtilProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr()));
190 MessageLoop::current()->Run(); 190 MessageLoop::current()->Run();
191 EXPECT_EQ(PLATFORM_FILE_OK, error_); 191 EXPECT_EQ(File::FILE_OK, error_);
192 EXPECT_TRUE(PathExists(path_)); 192 EXPECT_TRUE(PathExists(path_));
193 EXPECT_NE(kInvalidPlatformFileValue, file_); 193 EXPECT_NE(kInvalidPlatformFileValue, file_);
194 194
195 // The file should be writable. 195 // The file should be writable.
196 #if defined(OS_WIN) 196 #if defined(OS_WIN)
197 HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); 197 HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
198 OVERLAPPED overlapped = {0}; 198 OVERLAPPED overlapped = {0};
199 overlapped.hEvent = hEvent; 199 overlapped.hEvent = hEvent;
200 DWORD bytes_written; 200 DWORD bytes_written;
201 if (!::WriteFile(file_, "test", 4, &bytes_written, &overlapped)) { 201 if (!::WriteFile(file_, "test", 4, &bytes_written, &overlapped)) {
(...skipping 26 matching lines...) Expand all
228 GetFileInfo(test_path(), &expected_info); 228 GetFileInfo(test_path(), &expected_info);
229 229
230 // Run. 230 // Run.
231 FileUtilProxy::GetFileInfo( 231 FileUtilProxy::GetFileInfo(
232 file_task_runner(), 232 file_task_runner(),
233 test_path(), 233 test_path(),
234 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 234 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
235 MessageLoop::current()->Run(); 235 MessageLoop::current()->Run();
236 236
237 // Verify. 237 // Verify.
238 EXPECT_EQ(PLATFORM_FILE_OK, error_); 238 EXPECT_EQ(File::FILE_OK, error_);
239 EXPECT_EQ(expected_info.size, file_info_.size); 239 EXPECT_EQ(expected_info.size, file_info_.size);
240 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 240 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
241 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 241 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
242 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 242 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
243 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed); 243 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed);
244 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 244 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
245 } 245 }
246 246
247 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) { 247 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) {
248 // Setup. 248 // Setup.
249 ASSERT_TRUE(base::CreateDirectory(test_path())); 249 ASSERT_TRUE(base::CreateDirectory(test_path()));
250 File::Info expected_info; 250 File::Info expected_info;
251 GetFileInfo(test_path(), &expected_info); 251 GetFileInfo(test_path(), &expected_info);
252 252
253 // Run. 253 // Run.
254 FileUtilProxy::GetFileInfo( 254 FileUtilProxy::GetFileInfo(
255 file_task_runner(), 255 file_task_runner(),
256 test_path(), 256 test_path(),
257 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 257 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
258 MessageLoop::current()->Run(); 258 MessageLoop::current()->Run();
259 259
260 // Verify. 260 // Verify.
261 EXPECT_EQ(PLATFORM_FILE_OK, error_); 261 EXPECT_EQ(File::FILE_OK, error_);
262 EXPECT_EQ(expected_info.size, file_info_.size); 262 EXPECT_EQ(expected_info.size, file_info_.size);
263 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 263 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
264 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 264 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
265 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 265 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
266 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed); 266 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed);
267 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 267 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
268 } 268 }
269 269
270 TEST_F(FileUtilProxyTest, Read) { 270 TEST_F(FileUtilProxyTest, Read) {
271 // Setup. 271 // Setup.
272 const char expected_data[] = "bleh"; 272 const char expected_data[] = "bleh";
273 int expected_bytes = arraysize(expected_data); 273 int expected_bytes = arraysize(expected_data);
274 ASSERT_EQ(expected_bytes, 274 ASSERT_EQ(expected_bytes,
275 file_util::WriteFile(test_path(), expected_data, expected_bytes)); 275 file_util::WriteFile(test_path(), expected_data, expected_bytes));
276 276
277 // Run. 277 // Run.
278 FileUtilProxy::Read( 278 FileUtilProxy::Read(
279 file_task_runner(), 279 file_task_runner(),
280 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_READ), 280 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_READ),
281 0, // offset 281 0, // offset
282 128, 282 128,
283 Bind(&FileUtilProxyTest::DidRead, weak_factory_.GetWeakPtr())); 283 Bind(&FileUtilProxyTest::DidRead, weak_factory_.GetWeakPtr()));
284 MessageLoop::current()->Run(); 284 MessageLoop::current()->Run();
285 285
286 // Verify. 286 // Verify.
287 EXPECT_EQ(PLATFORM_FILE_OK, error_); 287 EXPECT_EQ(File::FILE_OK, error_);
288 EXPECT_EQ(expected_bytes, static_cast<int>(buffer_.size())); 288 EXPECT_EQ(expected_bytes, static_cast<int>(buffer_.size()));
289 for (size_t i = 0; i < buffer_.size(); ++i) { 289 for (size_t i = 0; i < buffer_.size(); ++i) {
290 EXPECT_EQ(expected_data[i], buffer_[i]); 290 EXPECT_EQ(expected_data[i], buffer_[i]);
291 } 291 }
292 } 292 }
293 293
294 TEST_F(FileUtilProxyTest, WriteAndFlush) { 294 TEST_F(FileUtilProxyTest, WriteAndFlush) {
295 const char data[] = "foo!"; 295 const char data[] = "foo!";
296 int data_bytes = ARRAYSIZE_UNSAFE(data); 296 int data_bytes = ARRAYSIZE_UNSAFE(data);
297 PlatformFile file = GetTestPlatformFile( 297 PlatformFile file = GetTestPlatformFile(
298 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE); 298 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE);
299 299
300 FileUtilProxy::Write( 300 FileUtilProxy::Write(
301 file_task_runner(), 301 file_task_runner(),
302 file, 302 file,
303 0, // offset 303 0, // offset
304 data, 304 data,
305 data_bytes, 305 data_bytes,
306 Bind(&FileUtilProxyTest::DidWrite, weak_factory_.GetWeakPtr())); 306 Bind(&FileUtilProxyTest::DidWrite, weak_factory_.GetWeakPtr()));
307 MessageLoop::current()->Run(); 307 MessageLoop::current()->Run();
308 EXPECT_EQ(PLATFORM_FILE_OK, error_); 308 EXPECT_EQ(File::FILE_OK, error_);
309 EXPECT_EQ(data_bytes, bytes_written_); 309 EXPECT_EQ(data_bytes, bytes_written_);
310 310
311 // Flush the written data. (So that the following read should always 311 // Flush the written data. (So that the following read should always
312 // succeed. On some platforms it may work with or without this flush.) 312 // succeed. On some platforms it may work with or without this flush.)
313 FileUtilProxy::Flush( 313 FileUtilProxy::Flush(
314 file_task_runner(), 314 file_task_runner(),
315 file, 315 file,
316 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 316 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
317 MessageLoop::current()->Run(); 317 MessageLoop::current()->Run();
318 EXPECT_EQ(PLATFORM_FILE_OK, error_); 318 EXPECT_EQ(File::FILE_OK, error_);
319 319
320 // Verify the written data. 320 // Verify the written data.
321 char buffer[10]; 321 char buffer[10];
322 EXPECT_EQ(data_bytes, base::ReadFile(test_path(), buffer, data_bytes)); 322 EXPECT_EQ(data_bytes, base::ReadFile(test_path(), buffer, data_bytes));
323 for (int i = 0; i < data_bytes; ++i) { 323 for (int i = 0; i < data_bytes; ++i) {
324 EXPECT_EQ(data[i], buffer[i]); 324 EXPECT_EQ(data[i], buffer[i]);
325 } 325 }
326 } 326 }
327 327
328 TEST_F(FileUtilProxyTest, Touch) { 328 TEST_F(FileUtilProxyTest, Touch) {
329 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345); 329 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345);
330 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765); 330 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765);
331 331
332 FileUtilProxy::Touch( 332 FileUtilProxy::Touch(
333 file_task_runner(), 333 file_task_runner(),
334 GetTestPlatformFile(PLATFORM_FILE_CREATE | 334 GetTestPlatformFile(PLATFORM_FILE_CREATE |
335 PLATFORM_FILE_WRITE | 335 PLATFORM_FILE_WRITE |
336 PLATFORM_FILE_WRITE_ATTRIBUTES), 336 PLATFORM_FILE_WRITE_ATTRIBUTES),
337 last_accessed_time, 337 last_accessed_time,
338 last_modified_time, 338 last_modified_time,
339 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 339 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
340 MessageLoop::current()->Run(); 340 MessageLoop::current()->Run();
341 EXPECT_EQ(PLATFORM_FILE_OK, error_); 341 EXPECT_EQ(File::FILE_OK, error_);
342 342
343 File::Info info; 343 File::Info info;
344 GetFileInfo(test_path(), &info); 344 GetFileInfo(test_path(), &info);
345 345
346 // The returned values may only have the seconds precision, so we cast 346 // The returned values may only have the seconds precision, so we cast
347 // the double values to int here. 347 // the double values to int here.
348 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), 348 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()),
349 static_cast<int>(info.last_modified.ToDoubleT())); 349 static_cast<int>(info.last_modified.ToDoubleT()));
350 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), 350 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()),
351 static_cast<int>(info.last_accessed.ToDoubleT())); 351 static_cast<int>(info.last_accessed.ToDoubleT()));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 char buffer[53]; 401 char buffer[53];
402 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); 402 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53));
403 int i = 0; 403 int i = 0;
404 for (; i < 10; ++i) 404 for (; i < 10; ++i)
405 EXPECT_EQ(kTestData[i], buffer[i]); 405 EXPECT_EQ(kTestData[i], buffer[i]);
406 for (; i < 53; ++i) 406 for (; i < 53; ++i)
407 EXPECT_EQ(0, buffer[i]); 407 EXPECT_EQ(0, buffer[i]);
408 } 408 }
409 409
410 } // namespace base 410 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util_proxy.cc ('k') | chrome/browser/browsing_data/browsing_data_file_system_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698