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

Side by Side Diff: webkit/fileapi/file_system_operation_unittest.cc

Issue 9372044: Refactor FileSystemOperation to take callback for each method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflected kinuko's comments + Fixture for failing-Write -> Cancel pattern. Created 8 years, 10 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 "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/bind.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop.h" 12 #include "base/message_loop.h"
11 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
12 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/fileapi/file_system_callback_dispatcher.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_file_util.h" 17 #include "webkit/fileapi/file_system_file_util.h"
17 #include "webkit/fileapi/file_system_mount_point_provider.h" 18 #include "webkit/fileapi/file_system_mount_point_provider.h"
18 #include "webkit/fileapi/file_system_operation.h" 19 #include "webkit/fileapi/file_system_operation.h"
19 #include "webkit/fileapi/file_system_quota_util.h" 20 #include "webkit/fileapi/file_system_quota_util.h"
20 #include "webkit/fileapi/file_system_test_helper.h" 21 #include "webkit/fileapi/file_system_test_helper.h"
21 #include "webkit/fileapi/file_system_util.h" 22 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/fileapi/local_file_util.h" 23 #include "webkit/fileapi/local_file_util.h"
23 #include "webkit/fileapi/quota_file_util.h" 24 #include "webkit/fileapi/quota_file_util.h"
24 #include "webkit/quota/quota_manager.h" 25 #include "webkit/quota/quota_manager.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 }; 144 };
144 145
145 FilePath ASCIIToFilePath(const std::string& str) { 146 FilePath ASCIIToFilePath(const std::string& str) {
146 return FilePath().AppendASCII(str); 147 return FilePath().AppendASCII(str);
147 } 148 }
148 149
149 } // namespace (anonymous) 150 } // namespace (anonymous)
150 151
151 // Test class for FileSystemOperation. Note that this just tests low-level 152 // Test class for FileSystemOperation. Note that this just tests low-level
152 // operations but doesn't test OpenFileSystem. 153 // operations but doesn't test OpenFileSystem.
153 class FileSystemOperationTest : public testing::Test { 154 class FileSystemOperationTest
155 : public testing::Test,
156 public base::SupportsWeakPtr<FileSystemOperationTest> {
154 public: 157 public:
155 FileSystemOperationTest() 158 FileSystemOperationTest()
156 : status_(kFileOperationStatusNotSet), 159 : status_(kFileOperationStatusNotSet),
157 local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())) { 160 local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())) {
158 EXPECT_TRUE(base_.CreateUniqueTempDir()); 161 EXPECT_TRUE(base_.CreateUniqueTempDir());
159 } 162 }
160 163
161 FileSystemOperation* operation(); 164 FileSystemOperation* operation();
162 165
163 void set_status(int status) { status_ = status; }
164 int status() const { return status_; } 166 int status() const { return status_; }
165 void set_info(const base::PlatformFileInfo& info) { info_ = info; }
166 const base::PlatformFileInfo& info() const { return info_; } 167 const base::PlatformFileInfo& info() const { return info_; }
167 void set_path(const FilePath& path) { path_ = path; }
168 const FilePath& path() const { return path_; } 168 const FilePath& path() const { return path_; }
169 void set_entries(const std::vector<base::FileUtilProxy::Entry>& entries) {
170 entries_ = entries;
171 }
172 const std::vector<base::FileUtilProxy::Entry>& entries() const { 169 const std::vector<base::FileUtilProxy::Entry>& entries() const {
173 return entries_; 170 return entries_;
174 } 171 }
175 172
176 virtual void SetUp(); 173 virtual void SetUp();
177 virtual void TearDown(); 174 virtual void TearDown();
178 175
179 protected: 176 protected:
180 // Common temp base for nondestructive uses. 177 // Common temp base for nondestructive uses.
181 ScopedTempDir base_; 178 ScopedTempDir base_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 else 231 else
235 return FilePath(); 232 return FilePath();
236 } 233 }
237 234
238 FilePath CreateVirtualTemporaryDir() { 235 FilePath CreateVirtualTemporaryDir() {
239 return CreateVirtualTemporaryDirInDir(FilePath()); 236 return CreateVirtualTemporaryDirInDir(FilePath());
240 } 237 }
241 238
242 FileSystemTestOriginHelper test_helper_; 239 FileSystemTestOriginHelper test_helper_;
243 240
241 // Callbacks for recording test results.
242 FileSystemOperationInterface::StatusCallback RecordStatusCallback() {
243 return base::Bind(&FileSystemOperationTest::DidFinish, AsWeakPtr());
244 }
245
246 FileSystemOperationInterface::ReadDirectoryCallback
247 RecordReadDirectoryCallback() {
248 return base::Bind(&FileSystemOperationTest::DidReadDirectory, AsWeakPtr());
249 }
250
251 FileSystemOperationInterface::GetMetadataCallback RecordMetadataCallback() {
252 return base::Bind(&FileSystemOperationTest::DidGetMetadata, AsWeakPtr());
253 }
254
255 void DidFinish(base::PlatformFileError status) {
256 status_ = status;
257 }
258
259 void DidReadDirectory(
260 base::PlatformFileError status,
261 const std::vector<base::FileUtilProxy::Entry>& entries,
262 bool /* has_more */) {
263 entries_ = entries;
264 status_ = status;
265 }
266
267 void DidGetMetadata(base::PlatformFileError status,
268 const base::PlatformFileInfo& info,
269 const FilePath& platform_path) {
270 info_ = info;
271 path_ = platform_path;
272 status_ = status;
273 }
274
244 // For post-operation status. 275 // For post-operation status.
245 int status_; 276 int status_;
246 base::PlatformFileInfo info_; 277 base::PlatformFileInfo info_;
247 FilePath path_; 278 FilePath path_;
248 std::vector<base::FileUtilProxy::Entry> entries_; 279 std::vector<base::FileUtilProxy::Entry> entries_;
249 280
250 private: 281 private:
251 scoped_ptr<LocalFileUtil> local_file_util_; 282 scoped_ptr<LocalFileUtil> local_file_util_;
252 scoped_refptr<QuotaManager> quota_manager_; 283 scoped_refptr<QuotaManager> quota_manager_;
253 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; 284 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
254 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); 285 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
255 }; 286 };
256 287
257 namespace {
258
259 class MockDispatcher : public FileSystemCallbackDispatcher {
260 public:
261 explicit MockDispatcher(FileSystemOperationTest* test) : test_(test) { }
262
263 virtual void DidFail(base::PlatformFileError status) {
264 test_->set_status(status);
265 }
266
267 virtual void DidSucceed() {
268 test_->set_status(base::PLATFORM_FILE_OK);
269 }
270
271 virtual void DidReadMetadata(
272 const base::PlatformFileInfo& info,
273 const FilePath& platform_path) {
274 test_->set_info(info);
275 test_->set_path(platform_path);
276 test_->set_status(base::PLATFORM_FILE_OK);
277 }
278
279 virtual void DidReadDirectory(
280 const std::vector<base::FileUtilProxy::Entry>& entries,
281 bool /* has_more */) {
282 test_->set_entries(entries);
283 }
284
285 virtual void DidOpenFileSystem(const std::string&, const GURL&) {
286 NOTREACHED();
287 }
288
289 virtual void DidWrite(int64 bytes, bool complete) {
290 NOTREACHED();
291 }
292
293 private:
294 FileSystemOperationTest* test_;
295 };
296
297 } // namespace (anonymous)
298
299 void FileSystemOperationTest::SetUp() { 288 void FileSystemOperationTest::SetUp() {
300 FilePath base_dir = base_.path().AppendASCII("filesystem"); 289 FilePath base_dir = base_.path().AppendASCII("filesystem");
301 quota_manager_ = new MockQuotaManager( 290 quota_manager_ = new MockQuotaManager(
302 base_dir, test_helper_.origin(), test_helper_.storage_type()); 291 base_dir, test_helper_.origin(), test_helper_.storage_type());
303 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); 292 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get());
304 test_helper_.SetUp(base_dir, 293 test_helper_.SetUp(base_dir,
305 false /* unlimited quota */, 294 false /* unlimited quota */,
306 quota_manager_proxy_.get(), 295 quota_manager_proxy_.get(),
307 local_file_util_.get()); 296 local_file_util_.get());
308 } 297 }
309 298
310 void FileSystemOperationTest::TearDown() { 299 void FileSystemOperationTest::TearDown() {
311 // Let the client go away before dropping a ref of the quota manager proxy. 300 // Let the client go away before dropping a ref of the quota manager proxy.
312 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); 301 quota_manager_proxy()->SimulateQuotaManagerDestroyed();
313 quota_manager_ = NULL; 302 quota_manager_ = NULL;
314 quota_manager_proxy_ = NULL; 303 quota_manager_proxy_ = NULL;
315 test_helper_.TearDown(); 304 test_helper_.TearDown();
316 } 305 }
317 306
318 FileSystemOperation* FileSystemOperationTest::operation() { 307 FileSystemOperation* FileSystemOperationTest::operation() {
319 return test_helper_.NewOperation(new MockDispatcher(this)); 308 return test_helper_.NewOperation();
320 } 309 }
321 310
322 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { 311 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
323 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); 312 GURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a"))));
324 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); 313 GURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b"))));
325 operation()->Move(src, dest); 314 operation()->Move(src, dest, RecordStatusCallback());
326 MessageLoop::current()->RunAllPending(); 315 MessageLoop::current()->RunAllPending();
327 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 316 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
328 } 317 }
329 318
330 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { 319 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) {
331 FilePath src_dir_path(CreateVirtualTemporaryDir()); 320 FilePath src_dir_path(CreateVirtualTemporaryDir());
332 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); 321 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
333 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 322 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
323 RecordStatusCallback());
334 MessageLoop::current()->RunAllPending(); 324 MessageLoop::current()->RunAllPending();
335 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 325 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
336 } 326 }
337 327
338 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { 328 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) {
339 // Src exists and is dir. Dest is a file. 329 // Src exists and is dir. Dest is a file.
340 FilePath src_dir_path(CreateVirtualTemporaryDir()); 330 FilePath src_dir_path(CreateVirtualTemporaryDir());
341 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 331 FilePath dest_dir_path(CreateVirtualTemporaryDir());
342 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 332 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
343 333
344 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path)); 334 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path),
335 RecordStatusCallback());
345 MessageLoop::current()->RunAllPending(); 336 MessageLoop::current()->RunAllPending();
346 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 337 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
347 } 338 }
348 339
349 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { 340 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) {
350 // Src exists and is a directory. Dest is a non-empty directory. 341 // Src exists and is a directory. Dest is a non-empty directory.
351 FilePath src_dir_path(CreateVirtualTemporaryDir()); 342 FilePath src_dir_path(CreateVirtualTemporaryDir());
352 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 343 FilePath dest_dir_path(CreateVirtualTemporaryDir());
353 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 344 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
354 345
355 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 346 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
347 RecordStatusCallback());
356 MessageLoop::current()->RunAllPending(); 348 MessageLoop::current()->RunAllPending();
357 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 349 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
358 } 350 }
359 351
360 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { 352 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) {
361 // Src exists and is a file. Dest is a directory. 353 // Src exists and is a file. Dest is a directory.
362 FilePath src_dir_path(CreateVirtualTemporaryDir()); 354 FilePath src_dir_path(CreateVirtualTemporaryDir());
363 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 355 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
364 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 356 FilePath dest_dir_path(CreateVirtualTemporaryDir());
365 357
366 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path)); 358 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path),
359 RecordStatusCallback());
367 MessageLoop::current()->RunAllPending(); 360 MessageLoop::current()->RunAllPending();
368 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 361 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
369 } 362 }
370 363
371 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { 364 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) {
372 // Dest. parent path does not exist. 365 // Dest. parent path does not exist.
373 FilePath src_dir_path(CreateVirtualTemporaryDir()); 366 FilePath src_dir_path(CreateVirtualTemporaryDir());
374 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). 367 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")).
375 Append(FILE_PATH_LITERAL("NonexistingFile")); 368 Append(FILE_PATH_LITERAL("NonexistingFile"));
376 369
377 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file)); 370 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file),
371 RecordStatusCallback());
378 MessageLoop::current()->RunAllPending(); 372 MessageLoop::current()->RunAllPending();
379 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 373 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
380 } 374 }
381 375
382 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { 376 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
383 FilePath src_dir_path(CreateVirtualTemporaryDir()); 377 FilePath src_dir_path(CreateVirtualTemporaryDir());
384 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 378 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
385 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 379 FilePath dest_dir_path(CreateVirtualTemporaryDir());
386 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 380 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
387 381
388 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); 382 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path),
383 RecordStatusCallback());
389 MessageLoop::current()->RunAllPending(); 384 MessageLoop::current()->RunAllPending();
390 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 385 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
391 EXPECT_TRUE(VirtualFileExists(dest_file_path)); 386 EXPECT_TRUE(VirtualFileExists(dest_file_path));
392 387
393 // Move is considered 'write' access (for both side), and won't be counted 388 // Move is considered 'write' access (for both side), and won't be counted
394 // as read access. 389 // as read access.
395 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); 390 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count());
396 } 391 }
397 392
398 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { 393 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
399 FilePath src_dir_path(CreateVirtualTemporaryDir()); 394 FilePath src_dir_path(CreateVirtualTemporaryDir());
400 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 395 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
401 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 396 FilePath dest_dir_path(CreateVirtualTemporaryDir());
402 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); 397 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
403 398
404 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path)); 399 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path),
400 RecordStatusCallback());
405 MessageLoop::current()->RunAllPending(); 401 MessageLoop::current()->RunAllPending();
406 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 402 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
407 EXPECT_TRUE(VirtualFileExists(dest_file_path)); 403 EXPECT_TRUE(VirtualFileExists(dest_file_path));
408 } 404 }
409 405
410 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { 406 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) {
411 FilePath src_dir_path(CreateVirtualTemporaryDir()); 407 FilePath src_dir_path(CreateVirtualTemporaryDir());
412 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 408 FilePath dest_dir_path(CreateVirtualTemporaryDir());
413 409
414 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 410 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
411 RecordStatusCallback());
415 MessageLoop::current()->RunAllPending(); 412 MessageLoop::current()->RunAllPending();
416 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 413 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
417 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); 414 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
418 415
419 // Make sure we've overwritten but not moved the source under the |dest_dir|. 416 // Make sure we've overwritten but not moved the source under the |dest_dir|.
420 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); 417 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path));
421 EXPECT_FALSE(VirtualDirectoryExists( 418 EXPECT_FALSE(VirtualDirectoryExists(
422 dest_dir_path.Append(src_dir_path.BaseName()))); 419 dest_dir_path.Append(src_dir_path.BaseName())));
423 } 420 }
424 421
425 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { 422 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) {
426 FilePath src_dir_path(CreateVirtualTemporaryDir()); 423 FilePath src_dir_path(CreateVirtualTemporaryDir());
427 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); 424 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir());
428 FilePath dest_child_dir_path(dest_parent_dir_path. 425 FilePath dest_child_dir_path(dest_parent_dir_path.
429 Append(FILE_PATH_LITERAL("NewDirectory"))); 426 Append(FILE_PATH_LITERAL("NewDirectory")));
430 427
431 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); 428 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path),
429 RecordStatusCallback());
432 MessageLoop::current()->RunAllPending(); 430 MessageLoop::current()->RunAllPending();
433 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 431 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
434 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path)); 432 EXPECT_FALSE(VirtualDirectoryExists(src_dir_path));
435 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); 433 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path));
436 } 434 }
437 435
438 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { 436 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
439 FilePath src_dir_path(CreateVirtualTemporaryDir()); 437 FilePath src_dir_path(CreateVirtualTemporaryDir());
440 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); 438 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
441 FilePath grandchild_file_path( 439 FilePath grandchild_file_path(
442 CreateVirtualTemporaryFileInDir(child_dir_path)); 440 CreateVirtualTemporaryFileInDir(child_dir_path));
443 441
444 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 442 FilePath dest_dir_path(CreateVirtualTemporaryDir());
445 443
446 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 444 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path),
445 RecordStatusCallback());
447 MessageLoop::current()->RunAllPending(); 446 MessageLoop::current()->RunAllPending();
448 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 447 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
449 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( 448 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
450 child_dir_path.BaseName()))); 449 child_dir_path.BaseName())));
451 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( 450 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append(
452 child_dir_path.BaseName()).Append( 451 child_dir_path.BaseName()).Append(
453 grandchild_file_path.BaseName()))); 452 grandchild_file_path.BaseName())));
454 } 453 }
455 454
456 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { 455 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
457 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), 456 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))),
458 URLForPath(FilePath(FILE_PATH_LITERAL("b")))); 457 URLForPath(FilePath(FILE_PATH_LITERAL("b"))),
458 RecordStatusCallback());
459 MessageLoop::current()->RunAllPending(); 459 MessageLoop::current()->RunAllPending();
460 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 460 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
461 } 461 }
462 462
463 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { 463 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) {
464 FilePath src_dir_path(CreateVirtualTemporaryDir()); 464 FilePath src_dir_path(CreateVirtualTemporaryDir());
465 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); 465 FilePath dest_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
466 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 466 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
467 RecordStatusCallback());
467 MessageLoop::current()->RunAllPending(); 468 MessageLoop::current()->RunAllPending();
468 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 469 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
469 } 470 }
470 471
471 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { 472 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) {
472 // Src exists and is dir. Dest is a file. 473 // Src exists and is dir. Dest is a file.
473 FilePath src_dir_path(CreateVirtualTemporaryDir()); 474 FilePath src_dir_path(CreateVirtualTemporaryDir());
474 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 475 FilePath dest_dir_path(CreateVirtualTemporaryDir());
475 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 476 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
476 477
477 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path)); 478 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path),
479 RecordStatusCallback());
478 MessageLoop::current()->RunAllPending(); 480 MessageLoop::current()->RunAllPending();
479 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 481 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
480 } 482 }
481 483
482 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { 484 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) {
483 // Src exists and is a directory. Dest is a non-empty directory. 485 // Src exists and is a directory. Dest is a non-empty directory.
484 FilePath src_dir_path(CreateVirtualTemporaryDir()); 486 FilePath src_dir_path(CreateVirtualTemporaryDir());
485 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 487 FilePath dest_dir_path(CreateVirtualTemporaryDir());
486 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 488 FilePath child_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
487 489
488 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 490 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
491 RecordStatusCallback());
489 MessageLoop::current()->RunAllPending(); 492 MessageLoop::current()->RunAllPending();
490 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 493 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
491 } 494 }
492 495
493 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { 496 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) {
494 // Src exists and is a file. Dest is a directory. 497 // Src exists and is a file. Dest is a directory.
495 FilePath src_dir_path(CreateVirtualTemporaryDir()); 498 FilePath src_dir_path(CreateVirtualTemporaryDir());
496 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 499 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
497 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 500 FilePath dest_dir_path(CreateVirtualTemporaryDir());
498 501
499 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path)); 502 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path),
503 RecordStatusCallback());
500 MessageLoop::current()->RunAllPending(); 504 MessageLoop::current()->RunAllPending();
501 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 505 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
502 } 506 }
503 507
504 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { 508 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) {
505 // Dest. parent path does not exist. 509 // Dest. parent path does not exist.
506 FilePath src_dir_path(CreateVirtualTemporaryDir()); 510 FilePath src_dir_path(CreateVirtualTemporaryDir());
507 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); 511 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir"));
508 file_util::EnsureEndsWithSeparator(&nonexisting_path); 512 file_util::EnsureEndsWithSeparator(&nonexisting_path);
509 FilePath nonexisting_file_path(nonexisting_path.Append( 513 FilePath nonexisting_file_path(nonexisting_path.Append(
510 FILE_PATH_LITERAL("DontExistFile"))); 514 FILE_PATH_LITERAL("DontExistFile")));
511 515
512 operation()->Copy(URLForPath(src_dir_path), 516 operation()->Copy(URLForPath(src_dir_path),
513 URLForPath(nonexisting_file_path)); 517 URLForPath(nonexisting_file_path),
518 RecordStatusCallback());
514 MessageLoop::current()->RunAllPending(); 519 MessageLoop::current()->RunAllPending();
515 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 520 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
516 } 521 }
517 522
518 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) { 523 TEST_F(FileSystemOperationTest, TestCopyFailureByQuota) {
519 base::PlatformFileInfo info; 524 base::PlatformFileInfo info;
520 525
521 FilePath src_dir_path(CreateVirtualTemporaryDir()); 526 FilePath src_dir_path(CreateVirtualTemporaryDir());
522 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 527 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
523 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 528 FilePath dest_dir_path(CreateVirtualTemporaryDir());
524 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); 529 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
525 530
526 quota_manager_proxy()->SetQuota(test_helper_.origin(), 531 quota_manager_proxy()->SetQuota(test_helper_.origin(),
527 test_helper_.storage_type(), 532 test_helper_.storage_type(),
528 11); 533 11);
529 534
530 operation()->Truncate(URLForPath(src_file_path), 6); 535 operation()->Truncate(URLForPath(src_file_path), 6,
536 RecordStatusCallback());
531 MessageLoop::current()->RunAllPending(); 537 MessageLoop::current()->RunAllPending();
532 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 538 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
533 539
534 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); 540 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info));
535 EXPECT_EQ(6, info.size); 541 EXPECT_EQ(6, info.size);
536 542
537 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); 543 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
544 RecordStatusCallback());
538 MessageLoop::current()->RunAllPending(); 545 MessageLoop::current()->RunAllPending();
539 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); 546 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
540 EXPECT_FALSE(VirtualFileExists(dest_file_path)); 547 EXPECT_FALSE(VirtualFileExists(dest_file_path));
541 } 548 }
542 549
543 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { 550 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
544 FilePath src_dir_path(CreateVirtualTemporaryDir()); 551 FilePath src_dir_path(CreateVirtualTemporaryDir());
545 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 552 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
546 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 553 FilePath dest_dir_path(CreateVirtualTemporaryDir());
547 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path)); 554 FilePath dest_file_path(CreateVirtualTemporaryFileInDir(dest_dir_path));
548 555
549 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); 556 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
557 RecordStatusCallback());
550 MessageLoop::current()->RunAllPending(); 558 MessageLoop::current()->RunAllPending();
551 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 559 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
552 EXPECT_TRUE(VirtualFileExists(dest_file_path)); 560 EXPECT_TRUE(VirtualFileExists(dest_file_path));
553 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 561 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
554 } 562 }
555 563
556 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { 564 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
557 FilePath src_dir_path(CreateVirtualTemporaryDir()); 565 FilePath src_dir_path(CreateVirtualTemporaryDir());
558 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path)); 566 FilePath src_file_path(CreateVirtualTemporaryFileInDir(src_dir_path));
559 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 567 FilePath dest_dir_path(CreateVirtualTemporaryDir());
560 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); 568 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
561 569
562 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path)); 570 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
571 RecordStatusCallback());
563 MessageLoop::current()->RunAllPending(); 572 MessageLoop::current()->RunAllPending();
564 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 573 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
565 EXPECT_TRUE(VirtualFileExists(dest_file_path)); 574 EXPECT_TRUE(VirtualFileExists(dest_file_path));
566 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 575 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
567 } 576 }
568 577
569 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { 578 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
570 FilePath src_dir_path(CreateVirtualTemporaryDir()); 579 FilePath src_dir_path(CreateVirtualTemporaryDir());
571 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 580 FilePath dest_dir_path(CreateVirtualTemporaryDir());
572 581
573 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 582 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
583 RecordStatusCallback());
574 MessageLoop::current()->RunAllPending(); 584 MessageLoop::current()->RunAllPending();
575 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 585 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
576 586
577 // Make sure we've overwritten but not copied the source under the |dest_dir|. 587 // Make sure we've overwritten but not copied the source under the |dest_dir|.
578 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path)); 588 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path));
579 EXPECT_FALSE(VirtualDirectoryExists( 589 EXPECT_FALSE(VirtualDirectoryExists(
580 dest_dir_path.Append(src_dir_path.BaseName()))); 590 dest_dir_path.Append(src_dir_path.BaseName())));
581 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 591 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
582 } 592 }
583 593
584 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { 594 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
585 FilePath src_dir_path(CreateVirtualTemporaryDir()); 595 FilePath src_dir_path(CreateVirtualTemporaryDir());
586 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir()); 596 FilePath dest_parent_dir_path(CreateVirtualTemporaryDir());
587 FilePath dest_child_dir_path(dest_parent_dir_path. 597 FilePath dest_child_dir_path(dest_parent_dir_path.
588 Append(FILE_PATH_LITERAL("NewDirectory"))); 598 Append(FILE_PATH_LITERAL("NewDirectory")));
589 599
590 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path)); 600 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path),
601 RecordStatusCallback());
591 MessageLoop::current()->RunAllPending(); 602 MessageLoop::current()->RunAllPending();
592 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 603 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
593 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path)); 604 EXPECT_TRUE(VirtualDirectoryExists(dest_child_dir_path));
594 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 605 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
595 } 606 }
596 607
597 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { 608 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
598 FilePath src_dir_path(CreateVirtualTemporaryDir()); 609 FilePath src_dir_path(CreateVirtualTemporaryDir());
599 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path)); 610 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(src_dir_path));
600 FilePath grandchild_file_path( 611 FilePath grandchild_file_path(
601 CreateVirtualTemporaryFileInDir(child_dir_path)); 612 CreateVirtualTemporaryFileInDir(child_dir_path));
602 613
603 FilePath dest_dir_path(CreateVirtualTemporaryDir()); 614 FilePath dest_dir_path(CreateVirtualTemporaryDir());
604 615
605 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path)); 616 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
617 RecordStatusCallback());
606 MessageLoop::current()->RunAllPending(); 618 MessageLoop::current()->RunAllPending();
607 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 619 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
608 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append( 620 EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
609 child_dir_path.BaseName()))); 621 child_dir_path.BaseName())));
610 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append( 622 EXPECT_TRUE(VirtualFileExists(dest_dir_path.Append(
611 child_dir_path.BaseName()).Append( 623 child_dir_path.BaseName()).Append(
612 grandchild_file_path.BaseName()))); 624 grandchild_file_path.BaseName())));
613 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 625 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
614 } 626 }
615 627
616 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { 628 TEST_F(FileSystemOperationTest, TestCreateFileFailure) {
617 // Already existing file and exclusive true. 629 // Already existing file and exclusive true.
618 FilePath dir_path(CreateVirtualTemporaryDir()); 630 FilePath dir_path(CreateVirtualTemporaryDir());
619 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 631 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
620 operation()->CreateFile(URLForPath(file_path), true); 632 operation()->CreateFile(URLForPath(file_path), true,
633 RecordStatusCallback());
621 MessageLoop::current()->RunAllPending(); 634 MessageLoop::current()->RunAllPending();
622 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 635 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
623 } 636 }
624 637
625 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { 638 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) {
626 // Already existing file and exclusive false. 639 // Already existing file and exclusive false.
627 FilePath dir_path(CreateVirtualTemporaryDir()); 640 FilePath dir_path(CreateVirtualTemporaryDir());
628 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 641 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
629 operation()->CreateFile(URLForPath(file_path), false); 642 operation()->CreateFile(URLForPath(file_path), false,
643 RecordStatusCallback());
630 MessageLoop::current()->RunAllPending(); 644 MessageLoop::current()->RunAllPending();
631 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 645 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
632 EXPECT_TRUE(VirtualFileExists(file_path)); 646 EXPECT_TRUE(VirtualFileExists(file_path));
633 } 647 }
634 648
635 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) { 649 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) {
636 // File doesn't exist but exclusive is true. 650 // File doesn't exist but exclusive is true.
637 FilePath dir_path(CreateVirtualTemporaryDir()); 651 FilePath dir_path(CreateVirtualTemporaryDir());
638 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); 652 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
639 operation()->CreateFile(URLForPath(file_path), true); 653 operation()->CreateFile(URLForPath(file_path), true,
654 RecordStatusCallback());
640 MessageLoop::current()->RunAllPending(); 655 MessageLoop::current()->RunAllPending();
641 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 656 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
642 EXPECT_TRUE(VirtualFileExists(file_path)); 657 EXPECT_TRUE(VirtualFileExists(file_path));
643 } 658 }
644 659
645 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { 660 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) {
646 // Non existing file. 661 // Non existing file.
647 FilePath dir_path(CreateVirtualTemporaryDir()); 662 FilePath dir_path(CreateVirtualTemporaryDir());
648 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); 663 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist")));
649 operation()->CreateFile(URLForPath(file_path), false); 664 operation()->CreateFile(URLForPath(file_path), false,
665 RecordStatusCallback());
650 MessageLoop::current()->RunAllPending(); 666 MessageLoop::current()->RunAllPending();
651 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 667 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
652 } 668 }
653 669
654 TEST_F(FileSystemOperationTest, 670 TEST_F(FileSystemOperationTest,
655 TestCreateDirFailureDestParentDoesntExist) { 671 TestCreateDirFailureDestParentDoesntExist) {
656 // Dest. parent path does not exist. 672 // Dest. parent path does not exist.
657 FilePath nonexisting_path(FilePath( 673 FilePath nonexisting_path(FilePath(
658 FILE_PATH_LITERAL("DirDoesntExist"))); 674 FILE_PATH_LITERAL("DirDoesntExist")));
659 FilePath nonexisting_file_path(nonexisting_path.Append( 675 FilePath nonexisting_file_path(nonexisting_path.Append(
660 FILE_PATH_LITERAL("FileDoesntExist"))); 676 FILE_PATH_LITERAL("FileDoesntExist")));
661 operation()->CreateDirectory( 677 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false,
662 URLForPath(nonexisting_file_path), false, false); 678 RecordStatusCallback());
663 MessageLoop::current()->RunAllPending(); 679 MessageLoop::current()->RunAllPending();
664 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 680 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
665 } 681 }
666 682
667 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { 683 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) {
668 // Exclusive and dir existing at path. 684 // Exclusive and dir existing at path.
669 FilePath src_dir_path(CreateVirtualTemporaryDir()); 685 FilePath src_dir_path(CreateVirtualTemporaryDir());
670 operation()->CreateDirectory(URLForPath(src_dir_path), true, false); 686 operation()->CreateDirectory(URLForPath(src_dir_path), true, false,
687 RecordStatusCallback());
671 MessageLoop::current()->RunAllPending(); 688 MessageLoop::current()->RunAllPending();
672 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 689 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
673 } 690 }
674 691
675 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { 692 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) {
676 // Exclusive true and file existing at path. 693 // Exclusive true and file existing at path.
677 FilePath dir_path(CreateVirtualTemporaryDir()); 694 FilePath dir_path(CreateVirtualTemporaryDir());
678 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 695 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
679 operation()->CreateDirectory(URLForPath(file_path), true, false); 696 operation()->CreateDirectory(URLForPath(file_path), true, false,
697 RecordStatusCallback());
680 MessageLoop::current()->RunAllPending(); 698 MessageLoop::current()->RunAllPending();
681 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 699 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
682 } 700 }
683 701
684 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { 702 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) {
685 // Dir exists and exclusive is false. 703 // Dir exists and exclusive is false.
686 FilePath dir_path(CreateVirtualTemporaryDir()); 704 FilePath dir_path(CreateVirtualTemporaryDir());
687 operation()->CreateDirectory(URLForPath(dir_path), false, false); 705 operation()->CreateDirectory(URLForPath(dir_path), false, false,
706 RecordStatusCallback());
688 MessageLoop::current()->RunAllPending(); 707 MessageLoop::current()->RunAllPending();
689 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 708 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
690 709
691 // Dir doesn't exist. 710 // Dir doesn't exist.
692 FilePath nonexisting_dir_path(FilePath( 711 FilePath nonexisting_dir_path(FilePath(
693 FILE_PATH_LITERAL("nonexistingdir"))); 712 FILE_PATH_LITERAL("nonexistingdir")));
694 operation()->CreateDirectory( 713 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false,
695 URLForPath(nonexisting_dir_path), false, false); 714 RecordStatusCallback());
696 MessageLoop::current()->RunAllPending(); 715 MessageLoop::current()->RunAllPending();
697 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 716 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
698 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); 717 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
699 } 718 }
700 719
701 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { 720 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
702 // Dir doesn't exist. 721 // Dir doesn't exist.
703 FilePath nonexisting_dir_path(FilePath( 722 FilePath nonexisting_dir_path(FilePath(
704 FILE_PATH_LITERAL("nonexistingdir"))); 723 FILE_PATH_LITERAL("nonexistingdir")));
705 724
706 operation()->CreateDirectory( 725 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false,
707 URLForPath(nonexisting_dir_path), true, false); 726 RecordStatusCallback());
708 MessageLoop::current()->RunAllPending(); 727 MessageLoop::current()->RunAllPending();
709 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 728 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
710 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path)); 729 EXPECT_TRUE(VirtualDirectoryExists(nonexisting_dir_path));
711 } 730 }
712 731
713 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { 732 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) {
714 FilePath nonexisting_dir_path(FilePath( 733 FilePath nonexisting_dir_path(FilePath(
715 FILE_PATH_LITERAL("nonexistingdir"))); 734 FILE_PATH_LITERAL("nonexistingdir")));
716 operation()->GetMetadata(URLForPath(nonexisting_dir_path)); 735 operation()->GetMetadata(URLForPath(nonexisting_dir_path),
736 RecordMetadataCallback());
717 MessageLoop::current()->RunAllPending(); 737 MessageLoop::current()->RunAllPending();
718 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 738 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
719 739
720 operation()->FileExists(URLForPath(nonexisting_dir_path)); 740 operation()->FileExists(URLForPath(nonexisting_dir_path),
741 RecordStatusCallback());
721 MessageLoop::current()->RunAllPending(); 742 MessageLoop::current()->RunAllPending();
722 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 743 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
723 744
724 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); 745 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
725 operation()->DirectoryExists(URLForPath(nonexisting_dir_path)); 746 operation()->DirectoryExists(URLForPath(nonexisting_dir_path),
747 RecordStatusCallback());
726 MessageLoop::current()->RunAllPending(); 748 MessageLoop::current()->RunAllPending();
727 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 749 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
728 } 750 }
729 751
730 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { 752 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
731 FilePath dir_path(CreateVirtualTemporaryDir()); 753 FilePath dir_path(CreateVirtualTemporaryDir());
732 int read_access = 0; 754 int read_access = 0;
733 755
734 operation()->DirectoryExists(URLForPath(dir_path)); 756 operation()->DirectoryExists(URLForPath(dir_path),
757 RecordStatusCallback());
735 MessageLoop::current()->RunAllPending(); 758 MessageLoop::current()->RunAllPending();
736 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 759 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
737 ++read_access; 760 ++read_access;
738 761
739 operation()->GetMetadata(URLForPath(dir_path)); 762 operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback());
740 MessageLoop::current()->RunAllPending(); 763 MessageLoop::current()->RunAllPending();
741 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 764 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
742 EXPECT_TRUE(info().is_directory); 765 EXPECT_TRUE(info().is_directory);
743 EXPECT_EQ(PlatformPath(dir_path), path()); 766 EXPECT_EQ(PlatformPath(dir_path), path());
744 ++read_access; 767 ++read_access;
745 768
746 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 769 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
747 operation()->FileExists(URLForPath(file_path)); 770 operation()->FileExists(URLForPath(file_path), RecordStatusCallback());
748 MessageLoop::current()->RunAllPending(); 771 MessageLoop::current()->RunAllPending();
749 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 772 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
750 ++read_access; 773 ++read_access;
751 774
752 operation()->GetMetadata(URLForPath(file_path)); 775 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback());
753 MessageLoop::current()->RunAllPending(); 776 MessageLoop::current()->RunAllPending();
754 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 777 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
755 EXPECT_FALSE(info().is_directory); 778 EXPECT_FALSE(info().is_directory);
756 EXPECT_EQ(PlatformPath(file_path), path()); 779 EXPECT_EQ(PlatformPath(file_path), path());
757 ++read_access; 780 ++read_access;
758 781
759 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); 782 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count());
760 } 783 }
761 784
762 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { 785 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
763 FilePath dir_path(CreateVirtualTemporaryDir()); 786 FilePath dir_path(CreateVirtualTemporaryDir());
764 operation()->FileExists(URLForPath(dir_path)); 787 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback());
765 MessageLoop::current()->RunAllPending(); 788 MessageLoop::current()->RunAllPending();
766 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 789 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
767 790
768 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 791 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
769 ASSERT_FALSE(file_path.empty()); 792 ASSERT_FALSE(file_path.empty());
770 operation()->DirectoryExists(URLForPath(file_path)); 793 operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback());
771 MessageLoop::current()->RunAllPending(); 794 MessageLoop::current()->RunAllPending();
772 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 795 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
773 } 796 }
774 797
775 TEST_F(FileSystemOperationTest, TestReadDirFailure) { 798 TEST_F(FileSystemOperationTest, TestReadDirFailure) {
776 // Path doesn't exist 799 // Path doesn't exist
777 FilePath nonexisting_dir_path(FilePath( 800 FilePath nonexisting_dir_path(FilePath(
778 FILE_PATH_LITERAL("NonExistingDir"))); 801 FILE_PATH_LITERAL("NonExistingDir")));
779 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); 802 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
780 operation()->ReadDirectory(URLForPath(nonexisting_dir_path)); 803 operation()->ReadDirectory(URLForPath(nonexisting_dir_path),
804 RecordReadDirectoryCallback());
781 MessageLoop::current()->RunAllPending(); 805 MessageLoop::current()->RunAllPending();
782 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 806 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
783 807
784 // File exists. 808 // File exists.
785 FilePath dir_path(CreateVirtualTemporaryDir()); 809 FilePath dir_path(CreateVirtualTemporaryDir());
786 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 810 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
787 operation()->ReadDirectory(URLForPath(file_path)); 811 operation()->ReadDirectory(URLForPath(file_path),
812 RecordReadDirectoryCallback());
788 MessageLoop::current()->RunAllPending(); 813 MessageLoop::current()->RunAllPending();
789 // TODO(kkanetkar) crbug.com/54309 to change the error code. 814 // TODO(kkanetkar) crbug.com/54309 to change the error code.
790 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 815 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
791 } 816 }
792 817
793 TEST_F(FileSystemOperationTest, TestReadDirSuccess) { 818 TEST_F(FileSystemOperationTest, TestReadDirSuccess) {
794 // parent_dir 819 // parent_dir
795 // | | 820 // | |
796 // child_dir child_file 821 // child_dir child_file
797 // Verify reading parent_dir. 822 // Verify reading parent_dir.
798 FilePath parent_dir_path(CreateVirtualTemporaryDir()); 823 FilePath parent_dir_path(CreateVirtualTemporaryDir());
799 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); 824 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path));
800 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); 825 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
801 ASSERT_FALSE(child_dir_path.empty()); 826 ASSERT_FALSE(child_dir_path.empty());
802 827
803 operation()->ReadDirectory(URLForPath(parent_dir_path)); 828 operation()->ReadDirectory(URLForPath(parent_dir_path),
829 RecordReadDirectoryCallback());
804 MessageLoop::current()->RunAllPending(); 830 MessageLoop::current()->RunAllPending();
805 EXPECT_EQ(kFileOperationStatusNotSet, status()); 831 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
806 EXPECT_EQ(2u, entries().size()); 832 EXPECT_EQ(2u, entries().size());
807 833
808 for (size_t i = 0; i < entries().size(); ++i) { 834 for (size_t i = 0; i < entries().size(); ++i) {
809 if (entries()[i].is_directory) { 835 if (entries()[i].is_directory) {
810 EXPECT_EQ(child_dir_path.BaseName().value(), 836 EXPECT_EQ(child_dir_path.BaseName().value(),
811 entries()[i].name); 837 entries()[i].name);
812 } else { 838 } else {
813 EXPECT_EQ(child_file_path.BaseName().value(), 839 EXPECT_EQ(child_file_path.BaseName().value(),
814 entries()[i].name); 840 entries()[i].name);
815 } 841 }
816 } 842 }
817 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 843 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
818 } 844 }
819 845
820 TEST_F(FileSystemOperationTest, TestRemoveFailure) { 846 TEST_F(FileSystemOperationTest, TestRemoveFailure) {
821 // Path doesn't exist. 847 // Path doesn't exist.
822 FilePath nonexisting_path(FilePath( 848 FilePath nonexisting_path(FilePath(
823 FILE_PATH_LITERAL("NonExistingDir"))); 849 FILE_PATH_LITERAL("NonExistingDir")));
824 file_util::EnsureEndsWithSeparator(&nonexisting_path); 850 file_util::EnsureEndsWithSeparator(&nonexisting_path);
825 851
826 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */); 852 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */,
853 RecordStatusCallback());
827 MessageLoop::current()->RunAllPending(); 854 MessageLoop::current()->RunAllPending();
828 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 855 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
829 856
830 // It's an error to try to remove a non-empty directory if recursive flag 857 // It's an error to try to remove a non-empty directory if recursive flag
831 // is false. 858 // is false.
832 // parent_dir 859 // parent_dir
833 // | | 860 // | |
834 // child_dir child_file 861 // child_dir child_file
835 // Verify deleting parent_dir. 862 // Verify deleting parent_dir.
836 FilePath parent_dir_path(CreateVirtualTemporaryDir()); 863 FilePath parent_dir_path(CreateVirtualTemporaryDir());
837 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); 864 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path));
838 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); 865 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
839 ASSERT_FALSE(child_dir_path.empty()); 866 ASSERT_FALSE(child_dir_path.empty());
840 867
841 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */); 868 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */,
869 RecordStatusCallback());
842 MessageLoop::current()->RunAllPending(); 870 MessageLoop::current()->RunAllPending();
843 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 871 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
844 status()); 872 status());
845 } 873 }
846 874
847 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { 875 TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
848 FilePath empty_dir_path(CreateVirtualTemporaryDir()); 876 FilePath empty_dir_path(CreateVirtualTemporaryDir());
849 EXPECT_TRUE(VirtualDirectoryExists(empty_dir_path)); 877 EXPECT_TRUE(VirtualDirectoryExists(empty_dir_path));
850 878
851 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */); 879 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */,
880 RecordStatusCallback());
852 MessageLoop::current()->RunAllPending(); 881 MessageLoop::current()->RunAllPending();
853 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 882 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
854 EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path)); 883 EXPECT_FALSE(VirtualDirectoryExists(empty_dir_path));
855 884
856 // Removing a non-empty directory with recursive flag == true should be ok. 885 // Removing a non-empty directory with recursive flag == true should be ok.
857 // parent_dir 886 // parent_dir
858 // | | 887 // | |
859 // child_dir child_file 888 // child_dir child_file
860 // Verify deleting parent_dir. 889 // Verify deleting parent_dir.
861 FilePath parent_dir_path(CreateVirtualTemporaryDir()); 890 FilePath parent_dir_path(CreateVirtualTemporaryDir());
862 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path)); 891 FilePath child_file_path(CreateVirtualTemporaryFileInDir(parent_dir_path));
863 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path)); 892 FilePath child_dir_path(CreateVirtualTemporaryDirInDir(parent_dir_path));
864 ASSERT_FALSE(child_dir_path.empty()); 893 ASSERT_FALSE(child_dir_path.empty());
865 894
866 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */); 895 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */,
896 RecordStatusCallback());
867 MessageLoop::current()->RunAllPending(); 897 MessageLoop::current()->RunAllPending();
868 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 898 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
869 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path)); 899 EXPECT_FALSE(VirtualDirectoryExists(parent_dir_path));
870 900
871 // Remove is not a 'read' access. 901 // Remove is not a 'read' access.
872 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); 902 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count());
873 } 903 }
874 904
875 TEST_F(FileSystemOperationTest, TestTruncate) { 905 TEST_F(FileSystemOperationTest, TestTruncate) {
876 FilePath dir_path(CreateVirtualTemporaryDir()); 906 FilePath dir_path(CreateVirtualTemporaryDir());
877 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 907 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
878 908
879 char test_data[] = "test data"; 909 char test_data[] = "test data";
880 int data_size = static_cast<int>(sizeof(test_data)); 910 int data_size = static_cast<int>(sizeof(test_data));
881 EXPECT_EQ(data_size, 911 EXPECT_EQ(data_size,
882 file_util::WriteFile(PlatformPath(file_path), 912 file_util::WriteFile(PlatformPath(file_path),
883 test_data, data_size)); 913 test_data, data_size));
884 914
885 // Check that its length is the size of the data written. 915 // Check that its length is the size of the data written.
886 operation()->GetMetadata(URLForPath(file_path)); 916 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback());
887 MessageLoop::current()->RunAllPending(); 917 MessageLoop::current()->RunAllPending();
888 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 918 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
889 EXPECT_FALSE(info().is_directory); 919 EXPECT_FALSE(info().is_directory);
890 EXPECT_EQ(data_size, info().size); 920 EXPECT_EQ(data_size, info().size);
891 921
892 // Extend the file by truncating it. 922 // Extend the file by truncating it.
893 int length = 17; 923 int length = 17;
894 operation()->Truncate(URLForPath(file_path), length); 924 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback());
895 MessageLoop::current()->RunAllPending(); 925 MessageLoop::current()->RunAllPending();
896 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 926 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
897 927
898 // Check that its length is now 17 and that it's all zeroes after the test 928 // Check that its length is now 17 and that it's all zeroes after the test
899 // data. 929 // data.
900 base::PlatformFileInfo info; 930 base::PlatformFileInfo info;
901 931
902 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 932 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
903 EXPECT_EQ(length, info.size); 933 EXPECT_EQ(length, info.size);
904 char data[100]; 934 char data[100];
905 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); 935 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length));
906 for (int i = 0; i < length; ++i) { 936 for (int i = 0; i < length; ++i) {
907 if (i < static_cast<int>(sizeof(test_data))) 937 if (i < static_cast<int>(sizeof(test_data)))
908 EXPECT_EQ(test_data[i], data[i]); 938 EXPECT_EQ(test_data[i], data[i]);
909 else 939 else
910 EXPECT_EQ(0, data[i]); 940 EXPECT_EQ(0, data[i]);
911 } 941 }
912 942
913 // Shorten the file by truncating it. 943 // Shorten the file by truncating it.
914 length = 3; 944 length = 3;
915 operation()->Truncate(URLForPath(file_path), length); 945 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback());
916 MessageLoop::current()->RunAllPending(); 946 MessageLoop::current()->RunAllPending();
917 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 947 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
918 948
919 // Check that its length is now 3 and that it contains only bits of test data. 949 // Check that its length is now 3 and that it contains only bits of test data.
920 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 950 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
921 EXPECT_EQ(length, info.size); 951 EXPECT_EQ(length, info.size);
922 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); 952 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length));
923 for (int i = 0; i < length; ++i) 953 for (int i = 0; i < length; ++i)
924 EXPECT_EQ(test_data[i], data[i]); 954 EXPECT_EQ(test_data[i], data[i]);
925 955
926 // Truncate is not a 'read' access. (Here expected access count is 1 956 // Truncate is not a 'read' access. (Here expected access count is 1
927 // since we made 1 read access for GetMetadata.) 957 // since we made 1 read access for GetMetadata.)
928 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 958 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count());
929 } 959 }
930 960
931 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) { 961 TEST_F(FileSystemOperationTest, TestTruncateFailureByQuota) {
932 base::PlatformFileInfo info; 962 base::PlatformFileInfo info;
933 963
934 FilePath dir_path(CreateVirtualTemporaryDir()); 964 FilePath dir_path(CreateVirtualTemporaryDir());
935 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path)); 965 FilePath file_path(CreateVirtualTemporaryFileInDir(dir_path));
936 966
937 quota_manager_proxy()->SetQuota(test_helper_.origin(), 967 quota_manager_proxy()->SetQuota(test_helper_.origin(),
938 test_helper_.storage_type(), 968 test_helper_.storage_type(),
939 10); 969 10);
940 970
941 operation()->Truncate(URLForPath(file_path), 10); 971 operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback());
942 MessageLoop::current()->RunAllPending(); 972 MessageLoop::current()->RunAllPending();
943 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 973 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
944 974
945 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 975 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
946 EXPECT_EQ(10, info.size); 976 EXPECT_EQ(10, info.size);
947 977
948 operation()->Truncate(URLForPath(file_path), 11); 978 operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback());
949 MessageLoop::current()->RunAllPending(); 979 MessageLoop::current()->RunAllPending();
950 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); 980 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
951 981
952 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 982 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
953 EXPECT_EQ(10, info.size); 983 EXPECT_EQ(10, info.size);
954 } 984 }
955 985
956 TEST_F(FileSystemOperationTest, TestTouchFile) { 986 TEST_F(FileSystemOperationTest, TestTouchFile) {
957 FilePath file_path(CreateVirtualTemporaryFileInDir(FilePath())); 987 FilePath file_path(CreateVirtualTemporaryFileInDir(FilePath()));
958 FilePath platform_path = PlatformPath(file_path); 988 FilePath platform_path = PlatformPath(file_path);
959 989
960 base::PlatformFileInfo info; 990 base::PlatformFileInfo info;
961 991
962 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); 992 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info));
963 EXPECT_FALSE(info.is_directory); 993 EXPECT_FALSE(info.is_directory);
964 EXPECT_EQ(0, info.size); 994 EXPECT_EQ(0, info.size);
965 const base::Time last_modified = info.last_modified; 995 const base::Time last_modified = info.last_modified;
966 const base::Time last_accessed = info.last_accessed; 996 const base::Time last_accessed = info.last_accessed;
967 997
968 const base::Time new_modified_time = base::Time::UnixEpoch(); 998 const base::Time new_modified_time = base::Time::UnixEpoch();
969 const base::Time new_accessed_time = new_modified_time + 999 const base::Time new_accessed_time = new_modified_time +
970 base::TimeDelta::FromHours(77);; 1000 base::TimeDelta::FromHours(77);;
971 ASSERT_NE(last_modified, new_modified_time); 1001 ASSERT_NE(last_modified, new_modified_time);
972 ASSERT_NE(last_accessed, new_accessed_time); 1002 ASSERT_NE(last_accessed, new_accessed_time);
973 1003
974 operation()->TouchFile(URLForPath(file_path), new_accessed_time, 1004 operation()->TouchFile(
975 new_modified_time); 1005 URLForPath(file_path), new_accessed_time, new_modified_time,
1006 RecordStatusCallback());
976 MessageLoop::current()->RunAllPending(); 1007 MessageLoop::current()->RunAllPending();
977 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 1008 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
978 1009
979 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); 1010 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info));
980 // We compare as time_t here to lower our resolution, to avoid false 1011 // We compare as time_t here to lower our resolution, to avoid false
981 // negatives caused by conversion to the local filesystem's native 1012 // negatives caused by conversion to the local filesystem's native
982 // representation and back. 1013 // representation and back.
983 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); 1014 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT());
984 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); 1015 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT());
985 } 1016 }
986 1017
987 } // namespace fileapi 1018 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation_interface.h ('k') | webkit/fileapi/file_system_operation_write_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698