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

Side by Side Diff: base/files/file_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_path_watcher_unittest.cc ('k') | base/files/file_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_proxy.h" 5 #include "base/files/file_proxy.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 void DidWrite(File::Error error, 72 void DidWrite(File::Error error,
73 int bytes_written) { 73 int bytes_written) {
74 error_ = error; 74 error_ = error;
75 bytes_written_ = bytes_written; 75 bytes_written_ = bytes_written;
76 MessageLoop::current()->QuitWhenIdle(); 76 MessageLoop::current()->QuitWhenIdle();
77 } 77 }
78 78
79 protected: 79 protected:
80 void CreateProxy(uint32_t flags, FileProxy* proxy) { 80 void CreateProxy(uint32_t flags, FileProxy* proxy) {
81 proxy->CreateOrOpen( 81 proxy->CreateOrOpen(TestPath(), flags, Bind(&FileProxyTest::DidCreateOrOpen,
82 test_path(), flags, 82 weak_factory_.GetWeakPtr()));
83 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
84 RunLoop().Run(); 83 RunLoop().Run();
85 EXPECT_TRUE(proxy->IsValid()); 84 EXPECT_TRUE(proxy->IsValid());
86 } 85 }
87 86
88 TaskRunner* file_task_runner() const { 87 TaskRunner* file_task_runner() const {
89 return file_thread_.task_runner().get(); 88 return file_thread_.task_runner().get();
90 } 89 }
91 const FilePath& test_dir_path() const { return dir_.path(); } 90 const FilePath& TestDirPath() const { return dir_.GetPath(); }
92 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } 91 const FilePath TestPath() const { return dir_.GetPath().AppendASCII("test"); }
93 92
94 ScopedTempDir dir_; 93 ScopedTempDir dir_;
95 MessageLoopForIO message_loop_; 94 MessageLoopForIO message_loop_;
96 Thread file_thread_; 95 Thread file_thread_;
97 96
98 File::Error error_; 97 File::Error error_;
99 FilePath path_; 98 FilePath path_;
100 File::Info file_info_; 99 File::Info file_info_;
101 std::vector<char> buffer_; 100 std::vector<char> buffer_;
102 int bytes_written_; 101 int bytes_written_;
103 WeakPtrFactory<FileProxyTest> weak_factory_; 102 WeakPtrFactory<FileProxyTest> weak_factory_;
104 }; 103 };
105 104
106 TEST_F(FileProxyTest, CreateOrOpen_Create) { 105 TEST_F(FileProxyTest, CreateOrOpen_Create) {
107 FileProxy proxy(file_task_runner()); 106 FileProxy proxy(file_task_runner());
108 proxy.CreateOrOpen( 107 proxy.CreateOrOpen(
109 test_path(), 108 TestPath(), File::FLAG_CREATE | File::FLAG_READ,
110 File::FLAG_CREATE | File::FLAG_READ,
111 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 109 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
112 RunLoop().Run(); 110 RunLoop().Run();
113 111
114 EXPECT_EQ(File::FILE_OK, error_); 112 EXPECT_EQ(File::FILE_OK, error_);
115 EXPECT_TRUE(proxy.IsValid()); 113 EXPECT_TRUE(proxy.IsValid());
116 EXPECT_TRUE(proxy.created()); 114 EXPECT_TRUE(proxy.created());
117 EXPECT_TRUE(PathExists(test_path())); 115 EXPECT_TRUE(PathExists(TestPath()));
118 } 116 }
119 117
120 TEST_F(FileProxyTest, CreateOrOpen_Open) { 118 TEST_F(FileProxyTest, CreateOrOpen_Open) {
121 // Creates a file. 119 // Creates a file.
122 base::WriteFile(test_path(), NULL, 0); 120 base::WriteFile(TestPath(), NULL, 0);
123 ASSERT_TRUE(PathExists(test_path())); 121 ASSERT_TRUE(PathExists(TestPath()));
124 122
125 // Opens the created file. 123 // Opens the created file.
126 FileProxy proxy(file_task_runner()); 124 FileProxy proxy(file_task_runner());
127 proxy.CreateOrOpen( 125 proxy.CreateOrOpen(
128 test_path(), 126 TestPath(), File::FLAG_OPEN | File::FLAG_READ,
129 File::FLAG_OPEN | File::FLAG_READ,
130 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 127 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
131 RunLoop().Run(); 128 RunLoop().Run();
132 129
133 EXPECT_EQ(File::FILE_OK, error_); 130 EXPECT_EQ(File::FILE_OK, error_);
134 EXPECT_TRUE(proxy.IsValid()); 131 EXPECT_TRUE(proxy.IsValid());
135 EXPECT_FALSE(proxy.created()); 132 EXPECT_FALSE(proxy.created());
136 } 133 }
137 134
138 TEST_F(FileProxyTest, CreateOrOpen_OpenNonExistent) { 135 TEST_F(FileProxyTest, CreateOrOpen_OpenNonExistent) {
139 FileProxy proxy(file_task_runner()); 136 FileProxy proxy(file_task_runner());
140 proxy.CreateOrOpen( 137 proxy.CreateOrOpen(
141 test_path(), 138 TestPath(), File::FLAG_OPEN | File::FLAG_READ,
142 File::FLAG_OPEN | File::FLAG_READ,
143 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 139 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
144 RunLoop().Run(); 140 RunLoop().Run();
145 EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, error_); 141 EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, error_);
146 EXPECT_FALSE(proxy.IsValid()); 142 EXPECT_FALSE(proxy.IsValid());
147 EXPECT_FALSE(proxy.created()); 143 EXPECT_FALSE(proxy.created());
148 EXPECT_FALSE(PathExists(test_path())); 144 EXPECT_FALSE(PathExists(TestPath()));
149 } 145 }
150 146
151 TEST_F(FileProxyTest, CreateOrOpen_AbandonedCreate) { 147 TEST_F(FileProxyTest, CreateOrOpen_AbandonedCreate) {
152 bool prev = ThreadRestrictions::SetIOAllowed(false); 148 bool prev = ThreadRestrictions::SetIOAllowed(false);
153 { 149 {
154 FileProxy proxy(file_task_runner()); 150 FileProxy proxy(file_task_runner());
155 proxy.CreateOrOpen( 151 proxy.CreateOrOpen(
156 test_path(), 152 TestPath(), File::FLAG_CREATE | File::FLAG_READ,
157 File::FLAG_CREATE | File::FLAG_READ,
158 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 153 Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
159 } 154 }
160 RunLoop().Run(); 155 RunLoop().Run();
161 ThreadRestrictions::SetIOAllowed(prev); 156 ThreadRestrictions::SetIOAllowed(prev);
162 157
163 EXPECT_TRUE(PathExists(test_path())); 158 EXPECT_TRUE(PathExists(TestPath()));
164 } 159 }
165 160
166 TEST_F(FileProxyTest, Close) { 161 TEST_F(FileProxyTest, Close) {
167 // Creates a file. 162 // Creates a file.
168 FileProxy proxy(file_task_runner()); 163 FileProxy proxy(file_task_runner());
169 CreateProxy(File::FLAG_CREATE | File::FLAG_WRITE, &proxy); 164 CreateProxy(File::FLAG_CREATE | File::FLAG_WRITE, &proxy);
170 165
171 #if defined(OS_WIN) 166 #if defined(OS_WIN)
172 // This fails on Windows if the file is not closed. 167 // This fails on Windows if the file is not closed.
173 EXPECT_FALSE(base::Move(test_path(), test_dir_path().AppendASCII("new"))); 168 EXPECT_FALSE(base::Move(TestPath(), TestDirPath().AppendASCII("new")));
174 #endif 169 #endif
175 170
176 proxy.Close(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 171 proxy.Close(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
177 RunLoop().Run(); 172 RunLoop().Run();
178 EXPECT_EQ(File::FILE_OK, error_); 173 EXPECT_EQ(File::FILE_OK, error_);
179 EXPECT_FALSE(proxy.IsValid()); 174 EXPECT_FALSE(proxy.IsValid());
180 175
181 // Now it should pass on all platforms. 176 // Now it should pass on all platforms.
182 EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new"))); 177 EXPECT_TRUE(base::Move(TestPath(), TestDirPath().AppendASCII("new")));
183 } 178 }
184 179
185 TEST_F(FileProxyTest, CreateTemporary) { 180 TEST_F(FileProxyTest, CreateTemporary) {
186 { 181 {
187 FileProxy proxy(file_task_runner()); 182 FileProxy proxy(file_task_runner());
188 proxy.CreateTemporary( 183 proxy.CreateTemporary(
189 0 /* additional_file_flags */, 184 0 /* additional_file_flags */,
190 Bind(&FileProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr())); 185 Bind(&FileProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr()));
191 RunLoop().Run(); 186 RunLoop().Run();
192 187
(...skipping 12 matching lines...) Expand all
205 // Make sure the written data can be read from the returned path. 200 // Make sure the written data can be read from the returned path.
206 std::string data; 201 std::string data;
207 EXPECT_TRUE(ReadFileToString(path_, &data)); 202 EXPECT_TRUE(ReadFileToString(path_, &data));
208 EXPECT_EQ("test", data); 203 EXPECT_EQ("test", data);
209 204
210 // Make sure we can & do delete the created file to prevent leaks on the bots. 205 // Make sure we can & do delete the created file to prevent leaks on the bots.
211 EXPECT_TRUE(base::DeleteFile(path_, false)); 206 EXPECT_TRUE(base::DeleteFile(path_, false));
212 } 207 }
213 208
214 TEST_F(FileProxyTest, SetAndTake) { 209 TEST_F(FileProxyTest, SetAndTake) {
215 File file(test_path(), File::FLAG_CREATE | File::FLAG_READ); 210 File file(TestPath(), File::FLAG_CREATE | File::FLAG_READ);
216 ASSERT_TRUE(file.IsValid()); 211 ASSERT_TRUE(file.IsValid());
217 FileProxy proxy(file_task_runner()); 212 FileProxy proxy(file_task_runner());
218 EXPECT_FALSE(proxy.IsValid()); 213 EXPECT_FALSE(proxy.IsValid());
219 proxy.SetFile(std::move(file)); 214 proxy.SetFile(std::move(file));
220 EXPECT_TRUE(proxy.IsValid()); 215 EXPECT_TRUE(proxy.IsValid());
221 EXPECT_FALSE(file.IsValid()); 216 EXPECT_FALSE(file.IsValid());
222 217
223 file = proxy.TakeFile(); 218 file = proxy.TakeFile();
224 EXPECT_FALSE(proxy.IsValid()); 219 EXPECT_FALSE(proxy.IsValid());
225 EXPECT_TRUE(file.IsValid()); 220 EXPECT_TRUE(file.IsValid());
(...skipping 11 matching lines...) Expand all
237 FileProxy invalid_proxy(file_task_runner()); 232 FileProxy invalid_proxy(file_task_runner());
238 ASSERT_FALSE(invalid_proxy.IsValid()); 233 ASSERT_FALSE(invalid_proxy.IsValid());
239 234
240 base::File invalid_duplicate = invalid_proxy.DuplicateFile(); 235 base::File invalid_duplicate = invalid_proxy.DuplicateFile();
241 EXPECT_FALSE(invalid_proxy.IsValid()); 236 EXPECT_FALSE(invalid_proxy.IsValid());
242 EXPECT_FALSE(invalid_duplicate.IsValid()); 237 EXPECT_FALSE(invalid_duplicate.IsValid());
243 } 238 }
244 239
245 TEST_F(FileProxyTest, GetInfo) { 240 TEST_F(FileProxyTest, GetInfo) {
246 // Setup. 241 // Setup.
247 ASSERT_EQ(4, base::WriteFile(test_path(), "test", 4)); 242 ASSERT_EQ(4, base::WriteFile(TestPath(), "test", 4));
248 File::Info expected_info; 243 File::Info expected_info;
249 GetFileInfo(test_path(), &expected_info); 244 GetFileInfo(TestPath(), &expected_info);
250 245
251 // Run. 246 // Run.
252 FileProxy proxy(file_task_runner()); 247 FileProxy proxy(file_task_runner());
253 CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); 248 CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy);
254 proxy.GetInfo( 249 proxy.GetInfo(
255 Bind(&FileProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 250 Bind(&FileProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
256 RunLoop().Run(); 251 RunLoop().Run();
257 252
258 // Verify. 253 // Verify.
259 EXPECT_EQ(File::FILE_OK, error_); 254 EXPECT_EQ(File::FILE_OK, error_);
260 EXPECT_EQ(expected_info.size, file_info_.size); 255 EXPECT_EQ(expected_info.size, file_info_.size);
261 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 256 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
262 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 257 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
263 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 258 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
264 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 259 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
265 } 260 }
266 261
267 TEST_F(FileProxyTest, Read) { 262 TEST_F(FileProxyTest, Read) {
268 // Setup. 263 // Setup.
269 const char expected_data[] = "bleh"; 264 const char expected_data[] = "bleh";
270 int expected_bytes = arraysize(expected_data); 265 int expected_bytes = arraysize(expected_data);
271 ASSERT_EQ(expected_bytes, 266 ASSERT_EQ(expected_bytes,
272 base::WriteFile(test_path(), expected_data, expected_bytes)); 267 base::WriteFile(TestPath(), expected_data, expected_bytes));
273 268
274 // Run. 269 // Run.
275 FileProxy proxy(file_task_runner()); 270 FileProxy proxy(file_task_runner());
276 CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); 271 CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy);
277 272
278 proxy.Read(0, 128, Bind(&FileProxyTest::DidRead, weak_factory_.GetWeakPtr())); 273 proxy.Read(0, 128, Bind(&FileProxyTest::DidRead, weak_factory_.GetWeakPtr()));
279 RunLoop().Run(); 274 RunLoop().Run();
280 275
281 // Verify. 276 // Verify.
282 EXPECT_EQ(File::FILE_OK, error_); 277 EXPECT_EQ(File::FILE_OK, error_);
(...skipping 16 matching lines...) Expand all
299 EXPECT_EQ(data_bytes, bytes_written_); 294 EXPECT_EQ(data_bytes, bytes_written_);
300 295
301 // Flush the written data. (So that the following read should always 296 // Flush the written data. (So that the following read should always
302 // succeed. On some platforms it may work with or without this flush.) 297 // succeed. On some platforms it may work with or without this flush.)
303 proxy.Flush(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 298 proxy.Flush(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
304 RunLoop().Run(); 299 RunLoop().Run();
305 EXPECT_EQ(File::FILE_OK, error_); 300 EXPECT_EQ(File::FILE_OK, error_);
306 301
307 // Verify the written data. 302 // Verify the written data.
308 char buffer[10]; 303 char buffer[10];
309 EXPECT_EQ(data_bytes, base::ReadFile(test_path(), buffer, data_bytes)); 304 EXPECT_EQ(data_bytes, base::ReadFile(TestPath(), buffer, data_bytes));
310 for (int i = 0; i < data_bytes; ++i) { 305 for (int i = 0; i < data_bytes; ++i) {
311 EXPECT_EQ(data[i], buffer[i]); 306 EXPECT_EQ(data[i], buffer[i]);
312 } 307 }
313 } 308 }
314 309
315 #if defined(OS_ANDROID) 310 #if defined(OS_ANDROID)
316 // Flaky on Android, see http://crbug.com/489602 311 // Flaky on Android, see http://crbug.com/489602
317 #define MAYBE_SetTimes DISABLED_SetTimes 312 #define MAYBE_SetTimes DISABLED_SetTimes
318 #else 313 #else
319 #define MAYBE_SetTimes SetTimes 314 #define MAYBE_SetTimes SetTimes
320 #endif 315 #endif
321 TEST_F(FileProxyTest, MAYBE_SetTimes) { 316 TEST_F(FileProxyTest, MAYBE_SetTimes) {
322 FileProxy proxy(file_task_runner()); 317 FileProxy proxy(file_task_runner());
323 CreateProxy( 318 CreateProxy(
324 File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_WRITE_ATTRIBUTES, 319 File::FLAG_CREATE | File::FLAG_WRITE | File::FLAG_WRITE_ATTRIBUTES,
325 &proxy); 320 &proxy);
326 321
327 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345); 322 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345);
328 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765); 323 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765);
329 324
330 proxy.SetTimes(last_accessed_time, last_modified_time, 325 proxy.SetTimes(last_accessed_time, last_modified_time,
331 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 326 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
332 RunLoop().Run(); 327 RunLoop().Run();
333 EXPECT_EQ(File::FILE_OK, error_); 328 EXPECT_EQ(File::FILE_OK, error_);
334 329
335 File::Info info; 330 File::Info info;
336 GetFileInfo(test_path(), &info); 331 GetFileInfo(TestPath(), &info);
337 332
338 // The returned values may only have the seconds precision, so we cast 333 // The returned values may only have the seconds precision, so we cast
339 // the double values to int here. 334 // the double values to int here.
340 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), 335 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()),
341 static_cast<int>(info.last_modified.ToDoubleT())); 336 static_cast<int>(info.last_modified.ToDoubleT()));
342 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), 337 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()),
343 static_cast<int>(info.last_accessed.ToDoubleT())); 338 static_cast<int>(info.last_accessed.ToDoubleT()));
344 } 339 }
345 340
346 TEST_F(FileProxyTest, SetLength_Shrink) { 341 TEST_F(FileProxyTest, SetLength_Shrink) {
347 // Setup. 342 // Setup.
348 const char kTestData[] = "0123456789"; 343 const char kTestData[] = "0123456789";
349 ASSERT_EQ(10, base::WriteFile(test_path(), kTestData, 10)); 344 ASSERT_EQ(10, base::WriteFile(TestPath(), kTestData, 10));
350 File::Info info; 345 File::Info info;
351 GetFileInfo(test_path(), &info); 346 GetFileInfo(TestPath(), &info);
352 ASSERT_EQ(10, info.size); 347 ASSERT_EQ(10, info.size);
353 348
354 // Run. 349 // Run.
355 FileProxy proxy(file_task_runner()); 350 FileProxy proxy(file_task_runner());
356 CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy); 351 CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy);
357 proxy.SetLength(7, 352 proxy.SetLength(7,
358 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 353 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
359 RunLoop().Run(); 354 RunLoop().Run();
360 355
361 // Verify. 356 // Verify.
362 GetFileInfo(test_path(), &info); 357 GetFileInfo(TestPath(), &info);
363 ASSERT_EQ(7, info.size); 358 ASSERT_EQ(7, info.size);
364 359
365 char buffer[7]; 360 char buffer[7];
366 EXPECT_EQ(7, base::ReadFile(test_path(), buffer, 7)); 361 EXPECT_EQ(7, base::ReadFile(TestPath(), buffer, 7));
367 int i = 0; 362 int i = 0;
368 for (; i < 7; ++i) 363 for (; i < 7; ++i)
369 EXPECT_EQ(kTestData[i], buffer[i]); 364 EXPECT_EQ(kTestData[i], buffer[i]);
370 } 365 }
371 366
372 TEST_F(FileProxyTest, SetLength_Expand) { 367 TEST_F(FileProxyTest, SetLength_Expand) {
373 // Setup. 368 // Setup.
374 const char kTestData[] = "9876543210"; 369 const char kTestData[] = "9876543210";
375 ASSERT_EQ(10, base::WriteFile(test_path(), kTestData, 10)); 370 ASSERT_EQ(10, base::WriteFile(TestPath(), kTestData, 10));
376 File::Info info; 371 File::Info info;
377 GetFileInfo(test_path(), &info); 372 GetFileInfo(TestPath(), &info);
378 ASSERT_EQ(10, info.size); 373 ASSERT_EQ(10, info.size);
379 374
380 // Run. 375 // Run.
381 FileProxy proxy(file_task_runner()); 376 FileProxy proxy(file_task_runner());
382 CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy); 377 CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy);
383 proxy.SetLength(53, 378 proxy.SetLength(53,
384 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 379 Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
385 RunLoop().Run(); 380 RunLoop().Run();
386 381
387 // Verify. 382 // Verify.
388 GetFileInfo(test_path(), &info); 383 GetFileInfo(TestPath(), &info);
389 ASSERT_EQ(53, info.size); 384 ASSERT_EQ(53, info.size);
390 385
391 char buffer[53]; 386 char buffer[53];
392 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); 387 EXPECT_EQ(53, base::ReadFile(TestPath(), buffer, 53));
393 int i = 0; 388 int i = 0;
394 for (; i < 10; ++i) 389 for (; i < 10; ++i)
395 EXPECT_EQ(kTestData[i], buffer[i]); 390 EXPECT_EQ(kTestData[i], buffer[i]);
396 for (; i < 53; ++i) 391 for (; i < 53; ++i)
397 EXPECT_EQ(0, buffer[i]); 392 EXPECT_EQ(0, buffer[i]);
398 } 393 }
399 394
400 } // namespace base 395 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_unittest.cc ('k') | base/files/file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698