OLD | NEW |
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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 *quota_out = quota; | 225 *quota_out = quota; |
226 } | 226 } |
227 | 227 |
228 void GetUsageAndQuota(int64* usage, int64* quota) { | 228 void GetUsageAndQuota(int64* usage, int64* quota) { |
229 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; | 229 quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; |
230 quota_manager_->GetUsageAndQuota( | 230 quota_manager_->GetUsageAndQuota( |
231 test_helper_.origin(), | 231 test_helper_.origin(), |
232 test_helper_.storage_type(), | 232 test_helper_.storage_type(), |
233 base::Bind(&LocalFileSystemOperationTest::DidGetUsageAndQuota, | 233 base::Bind(&LocalFileSystemOperationTest::DidGetUsageAndQuota, |
234 &status, usage, quota)); | 234 &status, usage, quota)); |
235 MessageLoop::current()->RunAllPending(); | 235 MessageLoop::current()->RunUntilIdle(); |
236 ASSERT_EQ(quota::kQuotaStatusOk, status); | 236 ASSERT_EQ(quota::kQuotaStatusOk, status); |
237 } | 237 } |
238 | 238 |
239 void GenerateUniquePathInDir(const FilePath& dir, | 239 void GenerateUniquePathInDir(const FilePath& dir, |
240 FilePath* file_path, | 240 FilePath* file_path, |
241 int64* path_cost) { | 241 int64* path_cost) { |
242 int64 base_usage; | 242 int64 base_usage; |
243 GetUsageAndQuota(&base_usage, NULL); | 243 GetUsageAndQuota(&base_usage, NULL); |
244 *file_path = CreateUniqueFileInDir(dir); | 244 *file_path = CreateUniqueFileInDir(dir); |
245 operation()->Remove(URLForPath(*file_path), | 245 operation()->Remove(URLForPath(*file_path), |
246 false /* recursive */, | 246 false /* recursive */, |
247 base::Bind(&AssertFileErrorEq, | 247 base::Bind(&AssertFileErrorEq, |
248 base::PLATFORM_FILE_OK)); | 248 base::PLATFORM_FILE_OK)); |
249 MessageLoop::current()->RunAllPending(); | 249 MessageLoop::current()->RunUntilIdle(); |
250 | 250 |
251 int64 total_usage; | 251 int64 total_usage; |
252 GetUsageAndQuota(&total_usage, NULL); | 252 GetUsageAndQuota(&total_usage, NULL); |
253 *path_cost = total_usage - base_usage; | 253 *path_cost = total_usage - base_usage; |
254 } | 254 } |
255 | 255 |
256 void GrantQuotaForCurrentUsage() { | 256 void GrantQuotaForCurrentUsage() { |
257 int64 usage; | 257 int64 usage; |
258 GetUsageAndQuota(&usage, NULL); | 258 GetUsageAndQuota(&usage, NULL); |
259 quota_manager()->SetQuota(test_helper_.origin(), | 259 quota_manager()->SetQuota(test_helper_.origin(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 LocalFileSystemOperation* operation = test_helper_.NewOperation(); | 317 LocalFileSystemOperation* operation = test_helper_.NewOperation(); |
318 operation->operation_context()->set_change_observers(change_observers()); | 318 operation->operation_context()->set_change_observers(change_observers()); |
319 return operation; | 319 return operation; |
320 } | 320 } |
321 | 321 |
322 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDoesntExist) { | 322 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDoesntExist) { |
323 FileSystemURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); | 323 FileSystemURL src(URLForPath(FilePath(FILE_PATH_LITERAL("a")))); |
324 FileSystemURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); | 324 FileSystemURL dest(URLForPath(FilePath(FILE_PATH_LITERAL("b")))); |
325 change_observer()->ResetCount(); | 325 change_observer()->ResetCount(); |
326 operation()->Move(src, dest, RecordStatusCallback()); | 326 operation()->Move(src, dest, RecordStatusCallback()); |
327 MessageLoop::current()->RunAllPending(); | 327 MessageLoop::current()->RunUntilIdle(); |
328 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 328 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
329 EXPECT_TRUE(change_observer()->HasNoChange()); | 329 EXPECT_TRUE(change_observer()->HasNoChange()); |
330 } | 330 } |
331 | 331 |
332 TEST_F(LocalFileSystemOperationTest, TestMoveFailureContainsPath) { | 332 TEST_F(LocalFileSystemOperationTest, TestMoveFailureContainsPath) { |
333 FilePath src_dir_path(CreateUniqueDir()); | 333 FilePath src_dir_path(CreateUniqueDir()); |
334 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); | 334 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); |
335 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 335 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
336 RecordStatusCallback()); | 336 RecordStatusCallback()); |
337 MessageLoop::current()->RunAllPending(); | 337 MessageLoop::current()->RunUntilIdle(); |
338 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 338 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
339 EXPECT_TRUE(change_observer()->HasNoChange()); | 339 EXPECT_TRUE(change_observer()->HasNoChange()); |
340 } | 340 } |
341 | 341 |
342 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { | 342 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { |
343 // Src exists and is dir. Dest is a file. | 343 // Src exists and is dir. Dest is a file. |
344 FilePath src_dir_path(CreateUniqueDir()); | 344 FilePath src_dir_path(CreateUniqueDir()); |
345 FilePath dest_dir_path(CreateUniqueDir()); | 345 FilePath dest_dir_path(CreateUniqueDir()); |
346 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 346 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
347 | 347 |
348 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path), | 348 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_file_path), |
349 RecordStatusCallback()); | 349 RecordStatusCallback()); |
350 MessageLoop::current()->RunAllPending(); | 350 MessageLoop::current()->RunUntilIdle(); |
351 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 351 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
352 EXPECT_TRUE(change_observer()->HasNoChange()); | 352 EXPECT_TRUE(change_observer()->HasNoChange()); |
353 } | 353 } |
354 | 354 |
355 TEST_F(LocalFileSystemOperationTest, | 355 TEST_F(LocalFileSystemOperationTest, |
356 TestMoveFailureSrcFileExistsDestNonEmptyDir) { | 356 TestMoveFailureSrcFileExistsDestNonEmptyDir) { |
357 // Src exists and is a directory. Dest is a non-empty directory. | 357 // Src exists and is a directory. Dest is a non-empty directory. |
358 FilePath src_dir_path(CreateUniqueDir()); | 358 FilePath src_dir_path(CreateUniqueDir()); |
359 FilePath dest_dir_path(CreateUniqueDir()); | 359 FilePath dest_dir_path(CreateUniqueDir()); |
360 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); | 360 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); |
361 | 361 |
362 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 362 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
363 RecordStatusCallback()); | 363 RecordStatusCallback()); |
364 MessageLoop::current()->RunAllPending(); | 364 MessageLoop::current()->RunUntilIdle(); |
365 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 365 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
366 EXPECT_TRUE(change_observer()->HasNoChange()); | 366 EXPECT_TRUE(change_observer()->HasNoChange()); |
367 } | 367 } |
368 | 368 |
369 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { | 369 TEST_F(LocalFileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { |
370 // Src exists and is a file. Dest is a directory. | 370 // Src exists and is a file. Dest is a directory. |
371 FilePath src_dir_path(CreateUniqueDir()); | 371 FilePath src_dir_path(CreateUniqueDir()); |
372 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 372 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
373 FilePath dest_dir_path(CreateUniqueDir()); | 373 FilePath dest_dir_path(CreateUniqueDir()); |
374 | 374 |
375 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path), | 375 operation()->Move(URLForPath(src_file_path), URLForPath(dest_dir_path), |
376 RecordStatusCallback()); | 376 RecordStatusCallback()); |
377 MessageLoop::current()->RunAllPending(); | 377 MessageLoop::current()->RunUntilIdle(); |
378 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 378 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
379 EXPECT_TRUE(change_observer()->HasNoChange()); | 379 EXPECT_TRUE(change_observer()->HasNoChange()); |
380 } | 380 } |
381 | 381 |
382 TEST_F(LocalFileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { | 382 TEST_F(LocalFileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { |
383 // Dest. parent path does not exist. | 383 // Dest. parent path does not exist. |
384 FilePath src_dir_path(CreateUniqueDir()); | 384 FilePath src_dir_path(CreateUniqueDir()); |
385 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). | 385 FilePath nonexisting_file = FilePath(FILE_PATH_LITERAL("NonexistingDir")). |
386 Append(FILE_PATH_LITERAL("NonexistingFile")); | 386 Append(FILE_PATH_LITERAL("NonexistingFile")); |
387 | 387 |
388 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file), | 388 operation()->Move(URLForPath(src_dir_path), URLForPath(nonexisting_file), |
389 RecordStatusCallback()); | 389 RecordStatusCallback()); |
390 MessageLoop::current()->RunAllPending(); | 390 MessageLoop::current()->RunUntilIdle(); |
391 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 391 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
392 EXPECT_TRUE(change_observer()->HasNoChange()); | 392 EXPECT_TRUE(change_observer()->HasNoChange()); |
393 } | 393 } |
394 | 394 |
395 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { | 395 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { |
396 FilePath src_dir_path(CreateUniqueDir()); | 396 FilePath src_dir_path(CreateUniqueDir()); |
397 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 397 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
398 FilePath dest_dir_path(CreateUniqueDir()); | 398 FilePath dest_dir_path(CreateUniqueDir()); |
399 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 399 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
400 | 400 |
401 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), | 401 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
402 RecordStatusCallback()); | 402 RecordStatusCallback()); |
403 MessageLoop::current()->RunAllPending(); | 403 MessageLoop::current()->RunUntilIdle(); |
404 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 404 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
405 EXPECT_TRUE(FileExists(dest_file_path)); | 405 EXPECT_TRUE(FileExists(dest_file_path)); |
406 | 406 |
407 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 407 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
408 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 408 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
409 EXPECT_TRUE(change_observer()->HasNoChange()); | 409 EXPECT_TRUE(change_observer()->HasNoChange()); |
410 | 410 |
411 // Move is considered 'write' access (for both side), and won't be counted | 411 // Move is considered 'write' access (for both side), and won't be counted |
412 // as read access. | 412 // as read access. |
413 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); | 413 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); |
414 } | 414 } |
415 | 415 |
416 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { | 416 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { |
417 FilePath src_dir_path(CreateUniqueDir()); | 417 FilePath src_dir_path(CreateUniqueDir()); |
418 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 418 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
419 FilePath dest_dir_path(CreateUniqueDir()); | 419 FilePath dest_dir_path(CreateUniqueDir()); |
420 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 420 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
421 | 421 |
422 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), | 422 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), |
423 RecordStatusCallback()); | 423 RecordStatusCallback()); |
424 MessageLoop::current()->RunAllPending(); | 424 MessageLoop::current()->RunUntilIdle(); |
425 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 425 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
426 EXPECT_TRUE(FileExists(dest_file_path)); | 426 EXPECT_TRUE(FileExists(dest_file_path)); |
427 | 427 |
428 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 428 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
429 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 429 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
430 EXPECT_TRUE(change_observer()->HasNoChange()); | 430 EXPECT_TRUE(change_observer()->HasNoChange()); |
431 } | 431 } |
432 | 432 |
433 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { | 433 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { |
434 FilePath src_dir_path(CreateUniqueDir()); | 434 FilePath src_dir_path(CreateUniqueDir()); |
435 FilePath dest_dir_path(CreateUniqueDir()); | 435 FilePath dest_dir_path(CreateUniqueDir()); |
436 | 436 |
437 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 437 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
438 RecordStatusCallback()); | 438 RecordStatusCallback()); |
439 MessageLoop::current()->RunAllPending(); | 439 MessageLoop::current()->RunUntilIdle(); |
440 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 440 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
441 EXPECT_FALSE(DirectoryExists(src_dir_path)); | 441 EXPECT_FALSE(DirectoryExists(src_dir_path)); |
442 | 442 |
443 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 443 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
444 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 444 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
445 EXPECT_TRUE(change_observer()->HasNoChange()); | 445 EXPECT_TRUE(change_observer()->HasNoChange()); |
446 | 446 |
447 // Make sure we've overwritten but not moved the source under the |dest_dir|. | 447 // Make sure we've overwritten but not moved the source under the |dest_dir|. |
448 EXPECT_TRUE(DirectoryExists(dest_dir_path)); | 448 EXPECT_TRUE(DirectoryExists(dest_dir_path)); |
449 EXPECT_FALSE(DirectoryExists( | 449 EXPECT_FALSE(DirectoryExists( |
450 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); | 450 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
451 } | 451 } |
452 | 452 |
453 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { | 453 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { |
454 FilePath src_dir_path(CreateUniqueDir()); | 454 FilePath src_dir_path(CreateUniqueDir()); |
455 FilePath dest_parent_dir_path(CreateUniqueDir()); | 455 FilePath dest_parent_dir_path(CreateUniqueDir()); |
456 FilePath dest_child_dir_path(dest_parent_dir_path. | 456 FilePath dest_child_dir_path(dest_parent_dir_path. |
457 Append(FILE_PATH_LITERAL("NewDirectory"))); | 457 Append(FILE_PATH_LITERAL("NewDirectory"))); |
458 | 458 |
459 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 459 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
460 RecordStatusCallback()); | 460 RecordStatusCallback()); |
461 MessageLoop::current()->RunAllPending(); | 461 MessageLoop::current()->RunUntilIdle(); |
462 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 462 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
463 EXPECT_FALSE(DirectoryExists(src_dir_path)); | 463 EXPECT_FALSE(DirectoryExists(src_dir_path)); |
464 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); | 464 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); |
465 | 465 |
466 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 466 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
467 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 467 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
468 EXPECT_TRUE(change_observer()->HasNoChange()); | 468 EXPECT_TRUE(change_observer()->HasNoChange()); |
469 } | 469 } |
470 | 470 |
471 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { | 471 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { |
472 FilePath src_dir_path(CreateUniqueDir()); | 472 FilePath src_dir_path(CreateUniqueDir()); |
473 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); | 473 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); |
474 FilePath grandchild_file_path( | 474 FilePath grandchild_file_path( |
475 CreateUniqueFileInDir(child_dir_path)); | 475 CreateUniqueFileInDir(child_dir_path)); |
476 | 476 |
477 FilePath dest_dir_path(CreateUniqueDir()); | 477 FilePath dest_dir_path(CreateUniqueDir()); |
478 | 478 |
479 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 479 operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
480 RecordStatusCallback()); | 480 RecordStatusCallback()); |
481 MessageLoop::current()->RunAllPending(); | 481 MessageLoop::current()->RunUntilIdle(); |
482 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 482 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
483 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( | 483 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( |
484 VirtualPath::BaseName(child_dir_path)))); | 484 VirtualPath::BaseName(child_dir_path)))); |
485 EXPECT_TRUE(FileExists(dest_dir_path.Append( | 485 EXPECT_TRUE(FileExists(dest_dir_path.Append( |
486 VirtualPath::BaseName(child_dir_path)).Append( | 486 VirtualPath::BaseName(child_dir_path)).Append( |
487 VirtualPath::BaseName(grandchild_file_path)))); | 487 VirtualPath::BaseName(grandchild_file_path)))); |
488 | 488 |
489 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); | 489 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); |
490 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 490 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
491 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 491 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
492 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 492 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
493 EXPECT_TRUE(change_observer()->HasNoChange()); | 493 EXPECT_TRUE(change_observer()->HasNoChange()); |
494 } | 494 } |
495 | 495 |
496 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDoesntExist) { | 496 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDoesntExist) { |
497 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), | 497 operation()->Copy(URLForPath(FilePath(FILE_PATH_LITERAL("a"))), |
498 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), | 498 URLForPath(FilePath(FILE_PATH_LITERAL("b"))), |
499 RecordStatusCallback()); | 499 RecordStatusCallback()); |
500 MessageLoop::current()->RunAllPending(); | 500 MessageLoop::current()->RunUntilIdle(); |
501 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 501 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
502 EXPECT_TRUE(change_observer()->HasNoChange()); | 502 EXPECT_TRUE(change_observer()->HasNoChange()); |
503 } | 503 } |
504 | 504 |
505 TEST_F(LocalFileSystemOperationTest, TestCopyFailureContainsPath) { | 505 TEST_F(LocalFileSystemOperationTest, TestCopyFailureContainsPath) { |
506 FilePath src_dir_path(CreateUniqueDir()); | 506 FilePath src_dir_path(CreateUniqueDir()); |
507 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); | 507 FilePath dest_dir_path(CreateUniqueDirInDir(src_dir_path)); |
508 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 508 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
509 RecordStatusCallback()); | 509 RecordStatusCallback()); |
510 MessageLoop::current()->RunAllPending(); | 510 MessageLoop::current()->RunUntilIdle(); |
511 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 511 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
512 EXPECT_TRUE(change_observer()->HasNoChange()); | 512 EXPECT_TRUE(change_observer()->HasNoChange()); |
513 } | 513 } |
514 | 514 |
515 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { | 515 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { |
516 // Src exists and is dir. Dest is a file. | 516 // Src exists and is dir. Dest is a file. |
517 FilePath src_dir_path(CreateUniqueDir()); | 517 FilePath src_dir_path(CreateUniqueDir()); |
518 FilePath dest_dir_path(CreateUniqueDir()); | 518 FilePath dest_dir_path(CreateUniqueDir()); |
519 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 519 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
520 | 520 |
521 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path), | 521 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_file_path), |
522 RecordStatusCallback()); | 522 RecordStatusCallback()); |
523 MessageLoop::current()->RunAllPending(); | 523 MessageLoop::current()->RunUntilIdle(); |
524 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 524 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
525 EXPECT_TRUE(change_observer()->HasNoChange()); | 525 EXPECT_TRUE(change_observer()->HasNoChange()); |
526 } | 526 } |
527 | 527 |
528 TEST_F(LocalFileSystemOperationTest, | 528 TEST_F(LocalFileSystemOperationTest, |
529 TestCopyFailureSrcFileExistsDestNonEmptyDir) { | 529 TestCopyFailureSrcFileExistsDestNonEmptyDir) { |
530 // Src exists and is a directory. Dest is a non-empty directory. | 530 // Src exists and is a directory. Dest is a non-empty directory. |
531 FilePath src_dir_path(CreateUniqueDir()); | 531 FilePath src_dir_path(CreateUniqueDir()); |
532 FilePath dest_dir_path(CreateUniqueDir()); | 532 FilePath dest_dir_path(CreateUniqueDir()); |
533 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); | 533 FilePath child_file_path(CreateUniqueFileInDir(dest_dir_path)); |
534 | 534 |
535 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 535 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
536 RecordStatusCallback()); | 536 RecordStatusCallback()); |
537 MessageLoop::current()->RunAllPending(); | 537 MessageLoop::current()->RunUntilIdle(); |
538 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); | 538 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); |
539 EXPECT_TRUE(change_observer()->HasNoChange()); | 539 EXPECT_TRUE(change_observer()->HasNoChange()); |
540 } | 540 } |
541 | 541 |
542 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { | 542 TEST_F(LocalFileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { |
543 // Src exists and is a file. Dest is a directory. | 543 // Src exists and is a file. Dest is a directory. |
544 FilePath src_dir_path(CreateUniqueDir()); | 544 FilePath src_dir_path(CreateUniqueDir()); |
545 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 545 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
546 FilePath dest_dir_path(CreateUniqueDir()); | 546 FilePath dest_dir_path(CreateUniqueDir()); |
547 | 547 |
548 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path), | 548 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_dir_path), |
549 RecordStatusCallback()); | 549 RecordStatusCallback()); |
550 MessageLoop::current()->RunAllPending(); | 550 MessageLoop::current()->RunUntilIdle(); |
551 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 551 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
552 EXPECT_TRUE(change_observer()->HasNoChange()); | 552 EXPECT_TRUE(change_observer()->HasNoChange()); |
553 } | 553 } |
554 | 554 |
555 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 555 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { |
556 // Dest. parent path does not exist. | 556 // Dest. parent path does not exist. |
557 FilePath src_dir_path(CreateUniqueDir()); | 557 FilePath src_dir_path(CreateUniqueDir()); |
558 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); | 558 FilePath nonexisting_path = FilePath(FILE_PATH_LITERAL("DontExistDir")); |
559 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 559 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
560 FilePath nonexisting_file_path(nonexisting_path.Append( | 560 FilePath nonexisting_file_path(nonexisting_path.Append( |
561 FILE_PATH_LITERAL("DontExistFile"))); | 561 FILE_PATH_LITERAL("DontExistFile"))); |
562 | 562 |
563 operation()->Copy(URLForPath(src_dir_path), | 563 operation()->Copy(URLForPath(src_dir_path), |
564 URLForPath(nonexisting_file_path), | 564 URLForPath(nonexisting_file_path), |
565 RecordStatusCallback()); | 565 RecordStatusCallback()); |
566 MessageLoop::current()->RunAllPending(); | 566 MessageLoop::current()->RunUntilIdle(); |
567 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 567 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
568 EXPECT_TRUE(change_observer()->HasNoChange()); | 568 EXPECT_TRUE(change_observer()->HasNoChange()); |
569 } | 569 } |
570 | 570 |
571 TEST_F(LocalFileSystemOperationTest, TestCopyFailureByQuota) { | 571 TEST_F(LocalFileSystemOperationTest, TestCopyFailureByQuota) { |
572 base::PlatformFileInfo info; | 572 base::PlatformFileInfo info; |
573 | 573 |
574 FilePath src_dir_path(CreateUniqueDir()); | 574 FilePath src_dir_path(CreateUniqueDir()); |
575 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 575 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
576 FilePath dest_dir_path(CreateUniqueDir()); | 576 FilePath dest_dir_path(CreateUniqueDir()); |
577 | 577 |
578 FilePath dest_file_path; | 578 FilePath dest_file_path; |
579 int64 dest_path_cost; | 579 int64 dest_path_cost; |
580 GenerateUniquePathInDir(dest_dir_path, &dest_file_path, &dest_path_cost); | 580 GenerateUniquePathInDir(dest_dir_path, &dest_file_path, &dest_path_cost); |
581 | 581 |
582 GrantQuotaForCurrentUsage(); | 582 GrantQuotaForCurrentUsage(); |
583 AddQuota(6); | 583 AddQuota(6); |
584 | 584 |
585 operation()->Truncate(URLForPath(src_file_path), 6, | 585 operation()->Truncate(URLForPath(src_file_path), 6, |
586 RecordStatusCallback()); | 586 RecordStatusCallback()); |
587 MessageLoop::current()->RunAllPending(); | 587 MessageLoop::current()->RunUntilIdle(); |
588 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 588 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
589 | 589 |
590 AddQuota(6 + dest_path_cost - 1); | 590 AddQuota(6 + dest_path_cost - 1); |
591 | 591 |
592 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); | 592 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(src_file_path), &info)); |
593 EXPECT_EQ(6, info.size); | 593 EXPECT_EQ(6, info.size); |
594 | 594 |
595 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 595 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
596 RecordStatusCallback()); | 596 RecordStatusCallback()); |
597 MessageLoop::current()->RunAllPending(); | 597 MessageLoop::current()->RunUntilIdle(); |
598 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 598 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
599 EXPECT_FALSE(FileExists(dest_file_path)); | 599 EXPECT_FALSE(FileExists(dest_file_path)); |
600 } | 600 } |
601 | 601 |
602 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { | 602 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { |
603 FilePath src_dir_path(CreateUniqueDir()); | 603 FilePath src_dir_path(CreateUniqueDir()); |
604 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 604 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
605 FilePath dest_dir_path(CreateUniqueDir()); | 605 FilePath dest_dir_path(CreateUniqueDir()); |
606 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); | 606 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); |
607 | 607 |
608 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 608 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
609 RecordStatusCallback()); | 609 RecordStatusCallback()); |
610 MessageLoop::current()->RunAllPending(); | 610 MessageLoop::current()->RunUntilIdle(); |
611 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 611 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
612 EXPECT_TRUE(FileExists(dest_file_path)); | 612 EXPECT_TRUE(FileExists(dest_file_path)); |
613 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 613 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
614 | 614 |
615 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 615 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
616 EXPECT_TRUE(change_observer()->HasNoChange()); | 616 EXPECT_TRUE(change_observer()->HasNoChange()); |
617 } | 617 } |
618 | 618 |
619 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { | 619 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { |
620 FilePath src_dir_path(CreateUniqueDir()); | 620 FilePath src_dir_path(CreateUniqueDir()); |
621 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); | 621 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); |
622 FilePath dest_dir_path(CreateUniqueDir()); | 622 FilePath dest_dir_path(CreateUniqueDir()); |
623 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); | 623 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); |
624 | 624 |
625 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), | 625 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), |
626 RecordStatusCallback()); | 626 RecordStatusCallback()); |
627 MessageLoop::current()->RunAllPending(); | 627 MessageLoop::current()->RunUntilIdle(); |
628 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 628 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
629 EXPECT_TRUE(FileExists(dest_file_path)); | 629 EXPECT_TRUE(FileExists(dest_file_path)); |
630 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 630 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
631 | 631 |
632 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); | 632 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); |
633 EXPECT_TRUE(change_observer()->HasNoChange()); | 633 EXPECT_TRUE(change_observer()->HasNoChange()); |
634 } | 634 } |
635 | 635 |
636 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { | 636 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { |
637 FilePath src_dir_path(CreateUniqueDir()); | 637 FilePath src_dir_path(CreateUniqueDir()); |
638 FilePath dest_dir_path(CreateUniqueDir()); | 638 FilePath dest_dir_path(CreateUniqueDir()); |
639 | 639 |
640 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 640 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
641 RecordStatusCallback()); | 641 RecordStatusCallback()); |
642 MessageLoop::current()->RunAllPending(); | 642 MessageLoop::current()->RunUntilIdle(); |
643 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 643 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
644 | 644 |
645 // Make sure we've overwritten but not copied the source under the |dest_dir|. | 645 // Make sure we've overwritten but not copied the source under the |dest_dir|. |
646 EXPECT_TRUE(DirectoryExists(dest_dir_path)); | 646 EXPECT_TRUE(DirectoryExists(dest_dir_path)); |
647 EXPECT_FALSE(DirectoryExists( | 647 EXPECT_FALSE(DirectoryExists( |
648 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); | 648 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); |
649 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 649 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
650 | 650 |
651 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 651 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
652 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 652 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
653 EXPECT_TRUE(change_observer()->HasNoChange()); | 653 EXPECT_TRUE(change_observer()->HasNoChange()); |
654 } | 654 } |
655 | 655 |
656 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { | 656 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { |
657 FilePath src_dir_path(CreateUniqueDir()); | 657 FilePath src_dir_path(CreateUniqueDir()); |
658 FilePath dest_parent_dir_path(CreateUniqueDir()); | 658 FilePath dest_parent_dir_path(CreateUniqueDir()); |
659 FilePath dest_child_dir_path(dest_parent_dir_path. | 659 FilePath dest_child_dir_path(dest_parent_dir_path. |
660 Append(FILE_PATH_LITERAL("NewDirectory"))); | 660 Append(FILE_PATH_LITERAL("NewDirectory"))); |
661 | 661 |
662 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), | 662 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), |
663 RecordStatusCallback()); | 663 RecordStatusCallback()); |
664 MessageLoop::current()->RunAllPending(); | 664 MessageLoop::current()->RunUntilIdle(); |
665 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 665 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
666 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); | 666 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); |
667 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 667 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
668 | 668 |
669 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 669 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
670 EXPECT_TRUE(change_observer()->HasNoChange()); | 670 EXPECT_TRUE(change_observer()->HasNoChange()); |
671 } | 671 } |
672 | 672 |
673 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { | 673 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { |
674 FilePath src_dir_path(CreateUniqueDir()); | 674 FilePath src_dir_path(CreateUniqueDir()); |
675 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); | 675 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); |
676 FilePath grandchild_file_path( | 676 FilePath grandchild_file_path( |
677 CreateUniqueFileInDir(child_dir_path)); | 677 CreateUniqueFileInDir(child_dir_path)); |
678 | 678 |
679 FilePath dest_dir_path(CreateUniqueDir()); | 679 FilePath dest_dir_path(CreateUniqueDir()); |
680 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), | 680 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), |
681 RecordStatusCallback()); | 681 RecordStatusCallback()); |
682 MessageLoop::current()->RunAllPending(); | 682 MessageLoop::current()->RunUntilIdle(); |
683 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 683 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
684 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( | 684 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( |
685 VirtualPath::BaseName(child_dir_path)))); | 685 VirtualPath::BaseName(child_dir_path)))); |
686 EXPECT_TRUE(FileExists(dest_dir_path.Append( | 686 EXPECT_TRUE(FileExists(dest_dir_path.Append( |
687 VirtualPath::BaseName(child_dir_path)).Append( | 687 VirtualPath::BaseName(child_dir_path)).Append( |
688 VirtualPath::BaseName(grandchild_file_path)))); | 688 VirtualPath::BaseName(grandchild_file_path)))); |
689 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 689 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
690 | 690 |
691 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); | 691 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); |
692 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 692 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
(...skipping 11 matching lines...) Expand all Loading... |
704 FilePath dest_file_path(dest_dir_path.Append( | 704 FilePath dest_file_path(dest_dir_path.Append( |
705 src_local_disk_file_path.BaseName())); | 705 src_local_disk_file_path.BaseName())); |
706 FileSystemURL dest_file_url = URLForPath(dest_file_path); | 706 FileSystemURL dest_file_url = URLForPath(dest_file_path); |
707 int64 before_usage; | 707 int64 before_usage; |
708 GetUsageAndQuota(&before_usage, NULL); | 708 GetUsageAndQuota(&before_usage, NULL); |
709 | 709 |
710 // Check that the file copied and corresponding usage increased. | 710 // Check that the file copied and corresponding usage increased. |
711 operation()->CopyInForeignFile(src_local_disk_file_path, | 711 operation()->CopyInForeignFile(src_local_disk_file_path, |
712 dest_file_url, | 712 dest_file_url, |
713 RecordStatusCallback()); | 713 RecordStatusCallback()); |
714 MessageLoop::current()->RunAllPending(); | 714 MessageLoop::current()->RunUntilIdle(); |
715 EXPECT_EQ(1, change_observer()->create_file_count()); | 715 EXPECT_EQ(1, change_observer()->create_file_count()); |
716 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 716 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
717 EXPECT_TRUE(FileExists(dest_file_path)); | 717 EXPECT_TRUE(FileExists(dest_file_path)); |
718 int64 after_usage; | 718 int64 after_usage; |
719 GetUsageAndQuota(&after_usage, NULL); | 719 GetUsageAndQuota(&after_usage, NULL); |
720 EXPECT_GT(after_usage, before_usage); | 720 EXPECT_GT(after_usage, before_usage); |
721 | 721 |
722 // Compare contents of src and copied file. | 722 // Compare contents of src and copied file. |
723 char buffer[100]; | 723 char buffer[100]; |
724 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath(dest_file_path), | 724 EXPECT_EQ(data_size, file_util::ReadFile(PlatformPath(dest_file_path), |
(...skipping 14 matching lines...) Expand all Loading... |
739 src_local_disk_file_path.BaseName())); | 739 src_local_disk_file_path.BaseName())); |
740 FileSystemURL dest_file_url = URLForPath(dest_file_path); | 740 FileSystemURL dest_file_url = URLForPath(dest_file_path); |
741 | 741 |
742 // Set quota of 0 which should force copy to fail by quota. | 742 // Set quota of 0 which should force copy to fail by quota. |
743 quota_manager()->SetQuota(dest_file_url.origin(), | 743 quota_manager()->SetQuota(dest_file_url.origin(), |
744 test_helper_.storage_type(), | 744 test_helper_.storage_type(), |
745 static_cast<int64>(0)); | 745 static_cast<int64>(0)); |
746 operation()->CopyInForeignFile(src_local_disk_file_path, | 746 operation()->CopyInForeignFile(src_local_disk_file_path, |
747 dest_file_url, | 747 dest_file_url, |
748 RecordStatusCallback()); | 748 RecordStatusCallback()); |
749 MessageLoop::current()->RunAllPending(); | 749 MessageLoop::current()->RunUntilIdle(); |
750 | 750 |
751 EXPECT_TRUE(!FileExists(dest_file_path)); | 751 EXPECT_TRUE(!FileExists(dest_file_path)); |
752 EXPECT_EQ(0, change_observer()->create_file_count()); | 752 EXPECT_EQ(0, change_observer()->create_file_count()); |
753 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 753 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
754 } | 754 } |
755 | 755 |
756 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { | 756 TEST_F(LocalFileSystemOperationTest, TestCreateFileFailure) { |
757 // Already existing file and exclusive true. | 757 // Already existing file and exclusive true. |
758 FilePath dir_path(CreateUniqueDir()); | 758 FilePath dir_path(CreateUniqueDir()); |
759 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 759 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
760 operation()->CreateFile(URLForPath(file_path), true, | 760 operation()->CreateFile(URLForPath(file_path), true, |
761 RecordStatusCallback()); | 761 RecordStatusCallback()); |
762 MessageLoop::current()->RunAllPending(); | 762 MessageLoop::current()->RunUntilIdle(); |
763 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 763 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
764 EXPECT_TRUE(change_observer()->HasNoChange()); | 764 EXPECT_TRUE(change_observer()->HasNoChange()); |
765 } | 765 } |
766 | 766 |
767 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileExists) { | 767 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileExists) { |
768 // Already existing file and exclusive false. | 768 // Already existing file and exclusive false. |
769 FilePath dir_path(CreateUniqueDir()); | 769 FilePath dir_path(CreateUniqueDir()); |
770 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 770 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
771 operation()->CreateFile(URLForPath(file_path), false, | 771 operation()->CreateFile(URLForPath(file_path), false, |
772 RecordStatusCallback()); | 772 RecordStatusCallback()); |
773 MessageLoop::current()->RunAllPending(); | 773 MessageLoop::current()->RunUntilIdle(); |
774 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 774 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
775 EXPECT_TRUE(FileExists(file_path)); | 775 EXPECT_TRUE(FileExists(file_path)); |
776 | 776 |
777 // The file was already there; did nothing. | 777 // The file was already there; did nothing. |
778 EXPECT_TRUE(change_observer()->HasNoChange()); | 778 EXPECT_TRUE(change_observer()->HasNoChange()); |
779 } | 779 } |
780 | 780 |
781 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessExclusive) { | 781 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessExclusive) { |
782 // File doesn't exist but exclusive is true. | 782 // File doesn't exist but exclusive is true. |
783 FilePath dir_path(CreateUniqueDir()); | 783 FilePath dir_path(CreateUniqueDir()); |
784 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 784 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); |
785 operation()->CreateFile(URLForPath(file_path), true, | 785 operation()->CreateFile(URLForPath(file_path), true, |
786 RecordStatusCallback()); | 786 RecordStatusCallback()); |
787 MessageLoop::current()->RunAllPending(); | 787 MessageLoop::current()->RunUntilIdle(); |
788 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 788 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
789 EXPECT_TRUE(FileExists(file_path)); | 789 EXPECT_TRUE(FileExists(file_path)); |
790 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 790 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
791 } | 791 } |
792 | 792 |
793 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { | 793 TEST_F(LocalFileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { |
794 // Non existing file. | 794 // Non existing file. |
795 FilePath dir_path(CreateUniqueDir()); | 795 FilePath dir_path(CreateUniqueDir()); |
796 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); | 796 FilePath file_path(dir_path.Append(FILE_PATH_LITERAL("FileDoesntExist"))); |
797 operation()->CreateFile(URLForPath(file_path), false, | 797 operation()->CreateFile(URLForPath(file_path), false, |
798 RecordStatusCallback()); | 798 RecordStatusCallback()); |
799 MessageLoop::current()->RunAllPending(); | 799 MessageLoop::current()->RunUntilIdle(); |
800 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 800 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
801 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); | 801 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); |
802 } | 802 } |
803 | 803 |
804 TEST_F(LocalFileSystemOperationTest, | 804 TEST_F(LocalFileSystemOperationTest, |
805 TestCreateDirFailureDestParentDoesntExist) { | 805 TestCreateDirFailureDestParentDoesntExist) { |
806 // Dest. parent path does not exist. | 806 // Dest. parent path does not exist. |
807 FilePath nonexisting_path(FilePath( | 807 FilePath nonexisting_path(FilePath( |
808 FILE_PATH_LITERAL("DirDoesntExist"))); | 808 FILE_PATH_LITERAL("DirDoesntExist"))); |
809 FilePath nonexisting_file_path(nonexisting_path.Append( | 809 FilePath nonexisting_file_path(nonexisting_path.Append( |
810 FILE_PATH_LITERAL("FileDoesntExist"))); | 810 FILE_PATH_LITERAL("FileDoesntExist"))); |
811 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false, | 811 operation()->CreateDirectory(URLForPath(nonexisting_file_path), false, false, |
812 RecordStatusCallback()); | 812 RecordStatusCallback()); |
813 MessageLoop::current()->RunAllPending(); | 813 MessageLoop::current()->RunUntilIdle(); |
814 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 814 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
815 EXPECT_TRUE(change_observer()->HasNoChange()); | 815 EXPECT_TRUE(change_observer()->HasNoChange()); |
816 } | 816 } |
817 | 817 |
818 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureDirExists) { | 818 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureDirExists) { |
819 // Exclusive and dir existing at path. | 819 // Exclusive and dir existing at path. |
820 FilePath src_dir_path(CreateUniqueDir()); | 820 FilePath src_dir_path(CreateUniqueDir()); |
821 operation()->CreateDirectory(URLForPath(src_dir_path), true, false, | 821 operation()->CreateDirectory(URLForPath(src_dir_path), true, false, |
822 RecordStatusCallback()); | 822 RecordStatusCallback()); |
823 MessageLoop::current()->RunAllPending(); | 823 MessageLoop::current()->RunUntilIdle(); |
824 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 824 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
825 EXPECT_TRUE(change_observer()->HasNoChange()); | 825 EXPECT_TRUE(change_observer()->HasNoChange()); |
826 } | 826 } |
827 | 827 |
828 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureFileExists) { | 828 TEST_F(LocalFileSystemOperationTest, TestCreateDirFailureFileExists) { |
829 // Exclusive true and file existing at path. | 829 // Exclusive true and file existing at path. |
830 FilePath dir_path(CreateUniqueDir()); | 830 FilePath dir_path(CreateUniqueDir()); |
831 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 831 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
832 operation()->CreateDirectory(URLForPath(file_path), true, false, | 832 operation()->CreateDirectory(URLForPath(file_path), true, false, |
833 RecordStatusCallback()); | 833 RecordStatusCallback()); |
834 MessageLoop::current()->RunAllPending(); | 834 MessageLoop::current()->RunUntilIdle(); |
835 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); | 835 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); |
836 EXPECT_TRUE(change_observer()->HasNoChange()); | 836 EXPECT_TRUE(change_observer()->HasNoChange()); |
837 } | 837 } |
838 | 838 |
839 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccess) { | 839 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccess) { |
840 // Dir exists and exclusive is false. | 840 // Dir exists and exclusive is false. |
841 FilePath dir_path(CreateUniqueDir()); | 841 FilePath dir_path(CreateUniqueDir()); |
842 operation()->CreateDirectory(URLForPath(dir_path), false, false, | 842 operation()->CreateDirectory(URLForPath(dir_path), false, false, |
843 RecordStatusCallback()); | 843 RecordStatusCallback()); |
844 MessageLoop::current()->RunAllPending(); | 844 MessageLoop::current()->RunUntilIdle(); |
845 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 845 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
846 EXPECT_TRUE(change_observer()->HasNoChange()); | 846 EXPECT_TRUE(change_observer()->HasNoChange()); |
847 | 847 |
848 // Dir doesn't exist. | 848 // Dir doesn't exist. |
849 FilePath nonexisting_dir_path(FilePath( | 849 FilePath nonexisting_dir_path(FilePath( |
850 FILE_PATH_LITERAL("nonexistingdir"))); | 850 FILE_PATH_LITERAL("nonexistingdir"))); |
851 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false, | 851 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false, |
852 RecordStatusCallback()); | 852 RecordStatusCallback()); |
853 MessageLoop::current()->RunAllPending(); | 853 MessageLoop::current()->RunUntilIdle(); |
854 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 854 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
855 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); | 855 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); |
856 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 856 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
857 } | 857 } |
858 | 858 |
859 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccessExclusive) { | 859 TEST_F(LocalFileSystemOperationTest, TestCreateDirSuccessExclusive) { |
860 // Dir doesn't exist. | 860 // Dir doesn't exist. |
861 FilePath nonexisting_dir_path(FilePath( | 861 FilePath nonexisting_dir_path(FilePath( |
862 FILE_PATH_LITERAL("nonexistingdir"))); | 862 FILE_PATH_LITERAL("nonexistingdir"))); |
863 | 863 |
864 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false, | 864 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false, |
865 RecordStatusCallback()); | 865 RecordStatusCallback()); |
866 MessageLoop::current()->RunAllPending(); | 866 MessageLoop::current()->RunUntilIdle(); |
867 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 867 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
868 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); | 868 EXPECT_TRUE(DirectoryExists(nonexisting_dir_path)); |
869 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 869 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
870 EXPECT_TRUE(change_observer()->HasNoChange()); | 870 EXPECT_TRUE(change_observer()->HasNoChange()); |
871 } | 871 } |
872 | 872 |
873 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataFailure) { | 873 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataFailure) { |
874 FilePath nonexisting_dir_path(FilePath( | 874 FilePath nonexisting_dir_path(FilePath( |
875 FILE_PATH_LITERAL("nonexistingdir"))); | 875 FILE_PATH_LITERAL("nonexistingdir"))); |
876 operation()->GetMetadata(URLForPath(nonexisting_dir_path), | 876 operation()->GetMetadata(URLForPath(nonexisting_dir_path), |
877 RecordMetadataCallback()); | 877 RecordMetadataCallback()); |
878 MessageLoop::current()->RunAllPending(); | 878 MessageLoop::current()->RunUntilIdle(); |
879 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 879 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
880 | 880 |
881 operation()->FileExists(URLForPath(nonexisting_dir_path), | 881 operation()->FileExists(URLForPath(nonexisting_dir_path), |
882 RecordStatusCallback()); | 882 RecordStatusCallback()); |
883 MessageLoop::current()->RunAllPending(); | 883 MessageLoop::current()->RunUntilIdle(); |
884 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 884 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
885 | 885 |
886 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 886 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
887 operation()->DirectoryExists(URLForPath(nonexisting_dir_path), | 887 operation()->DirectoryExists(URLForPath(nonexisting_dir_path), |
888 RecordStatusCallback()); | 888 RecordStatusCallback()); |
889 MessageLoop::current()->RunAllPending(); | 889 MessageLoop::current()->RunUntilIdle(); |
890 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 890 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
891 EXPECT_TRUE(change_observer()->HasNoChange()); | 891 EXPECT_TRUE(change_observer()->HasNoChange()); |
892 } | 892 } |
893 | 893 |
894 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { | 894 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { |
895 FilePath dir_path(CreateUniqueDir()); | 895 FilePath dir_path(CreateUniqueDir()); |
896 int read_access = 0; | 896 int read_access = 0; |
897 | 897 |
898 operation()->DirectoryExists(URLForPath(dir_path), | 898 operation()->DirectoryExists(URLForPath(dir_path), |
899 RecordStatusCallback()); | 899 RecordStatusCallback()); |
900 MessageLoop::current()->RunAllPending(); | 900 MessageLoop::current()->RunUntilIdle(); |
901 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 901 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
902 ++read_access; | 902 ++read_access; |
903 | 903 |
904 operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback()); | 904 operation()->GetMetadata(URLForPath(dir_path), RecordMetadataCallback()); |
905 MessageLoop::current()->RunAllPending(); | 905 MessageLoop::current()->RunUntilIdle(); |
906 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 906 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
907 EXPECT_TRUE(info().is_directory); | 907 EXPECT_TRUE(info().is_directory); |
908 EXPECT_EQ(FilePath(), path()); | 908 EXPECT_EQ(FilePath(), path()); |
909 ++read_access; | 909 ++read_access; |
910 | 910 |
911 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 911 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
912 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); | 912 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); |
913 MessageLoop::current()->RunAllPending(); | 913 MessageLoop::current()->RunUntilIdle(); |
914 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 914 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
915 ++read_access; | 915 ++read_access; |
916 | 916 |
917 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); | 917 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); |
918 MessageLoop::current()->RunAllPending(); | 918 MessageLoop::current()->RunUntilIdle(); |
919 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 919 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
920 EXPECT_FALSE(info().is_directory); | 920 EXPECT_FALSE(info().is_directory); |
921 EXPECT_EQ(PlatformPath(file_path), path()); | 921 EXPECT_EQ(PlatformPath(file_path), path()); |
922 ++read_access; | 922 ++read_access; |
923 | 923 |
924 EXPECT_EQ(read_access, | 924 EXPECT_EQ(read_access, |
925 quota_manager_proxy()->notify_storage_accessed_count()); | 925 quota_manager_proxy()->notify_storage_accessed_count()); |
926 EXPECT_TRUE(change_observer()->HasNoChange()); | 926 EXPECT_TRUE(change_observer()->HasNoChange()); |
927 } | 927 } |
928 | 928 |
929 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { | 929 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { |
930 FilePath dir_path(CreateUniqueDir()); | 930 FilePath dir_path(CreateUniqueDir()); |
931 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); | 931 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); |
932 MessageLoop::current()->RunAllPending(); | 932 MessageLoop::current()->RunUntilIdle(); |
933 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); | 933 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); |
934 | 934 |
935 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 935 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
936 ASSERT_FALSE(file_path.empty()); | 936 ASSERT_FALSE(file_path.empty()); |
937 operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback()); | 937 operation()->DirectoryExists(URLForPath(file_path), RecordStatusCallback()); |
938 MessageLoop::current()->RunAllPending(); | 938 MessageLoop::current()->RunUntilIdle(); |
939 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 939 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
940 } | 940 } |
941 | 941 |
942 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { | 942 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { |
943 // Path doesn't exist | 943 // Path doesn't exist |
944 FilePath nonexisting_dir_path(FilePath( | 944 FilePath nonexisting_dir_path(FilePath( |
945 FILE_PATH_LITERAL("NonExistingDir"))); | 945 FILE_PATH_LITERAL("NonExistingDir"))); |
946 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 946 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); |
947 operation()->ReadDirectory(URLForPath(nonexisting_dir_path), | 947 operation()->ReadDirectory(URLForPath(nonexisting_dir_path), |
948 RecordReadDirectoryCallback()); | 948 RecordReadDirectoryCallback()); |
949 MessageLoop::current()->RunAllPending(); | 949 MessageLoop::current()->RunUntilIdle(); |
950 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 950 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
951 | 951 |
952 // File exists. | 952 // File exists. |
953 FilePath dir_path(CreateUniqueDir()); | 953 FilePath dir_path(CreateUniqueDir()); |
954 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 954 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
955 operation()->ReadDirectory(URLForPath(file_path), | 955 operation()->ReadDirectory(URLForPath(file_path), |
956 RecordReadDirectoryCallback()); | 956 RecordReadDirectoryCallback()); |
957 MessageLoop::current()->RunAllPending(); | 957 MessageLoop::current()->RunUntilIdle(); |
958 // TODO(kkanetkar) crbug.com/54309 to change the error code. | 958 // TODO(kkanetkar) crbug.com/54309 to change the error code. |
959 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 959 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
960 EXPECT_TRUE(change_observer()->HasNoChange()); | 960 EXPECT_TRUE(change_observer()->HasNoChange()); |
961 } | 961 } |
962 | 962 |
963 TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) { | 963 TEST_F(LocalFileSystemOperationTest, TestReadDirSuccess) { |
964 // parent_dir | 964 // parent_dir |
965 // | | | 965 // | | |
966 // child_dir child_file | 966 // child_dir child_file |
967 // Verify reading parent_dir. | 967 // Verify reading parent_dir. |
968 FilePath parent_dir_path(CreateUniqueDir()); | 968 FilePath parent_dir_path(CreateUniqueDir()); |
969 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 969 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
970 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 970 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
971 ASSERT_FALSE(child_dir_path.empty()); | 971 ASSERT_FALSE(child_dir_path.empty()); |
972 | 972 |
973 operation()->ReadDirectory(URLForPath(parent_dir_path), | 973 operation()->ReadDirectory(URLForPath(parent_dir_path), |
974 RecordReadDirectoryCallback()); | 974 RecordReadDirectoryCallback()); |
975 MessageLoop::current()->RunAllPending(); | 975 MessageLoop::current()->RunUntilIdle(); |
976 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 976 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
977 EXPECT_EQ(2u, entries().size()); | 977 EXPECT_EQ(2u, entries().size()); |
978 | 978 |
979 for (size_t i = 0; i < entries().size(); ++i) { | 979 for (size_t i = 0; i < entries().size(); ++i) { |
980 if (entries()[i].is_directory) { | 980 if (entries()[i].is_directory) { |
981 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), | 981 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), |
982 entries()[i].name); | 982 entries()[i].name); |
983 } else { | 983 } else { |
984 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), | 984 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), |
985 entries()[i].name); | 985 entries()[i].name); |
986 } | 986 } |
987 } | 987 } |
988 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 988 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
989 EXPECT_TRUE(change_observer()->HasNoChange()); | 989 EXPECT_TRUE(change_observer()->HasNoChange()); |
990 } | 990 } |
991 | 991 |
992 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { | 992 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { |
993 // Path doesn't exist. | 993 // Path doesn't exist. |
994 FilePath nonexisting_path(FilePath( | 994 FilePath nonexisting_path(FilePath( |
995 FILE_PATH_LITERAL("NonExistingDir"))); | 995 FILE_PATH_LITERAL("NonExistingDir"))); |
996 file_util::EnsureEndsWithSeparator(&nonexisting_path); | 996 file_util::EnsureEndsWithSeparator(&nonexisting_path); |
997 | 997 |
998 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, | 998 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, |
999 RecordStatusCallback()); | 999 RecordStatusCallback()); |
1000 MessageLoop::current()->RunAllPending(); | 1000 MessageLoop::current()->RunUntilIdle(); |
1001 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 1001 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
1002 | 1002 |
1003 // It's an error to try to remove a non-empty directory if recursive flag | 1003 // It's an error to try to remove a non-empty directory if recursive flag |
1004 // is false. | 1004 // is false. |
1005 // parent_dir | 1005 // parent_dir |
1006 // | | | 1006 // | | |
1007 // child_dir child_file | 1007 // child_dir child_file |
1008 // Verify deleting parent_dir. | 1008 // Verify deleting parent_dir. |
1009 FilePath parent_dir_path(CreateUniqueDir()); | 1009 FilePath parent_dir_path(CreateUniqueDir()); |
1010 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 1010 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
1011 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 1011 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
1012 ASSERT_FALSE(child_dir_path.empty()); | 1012 ASSERT_FALSE(child_dir_path.empty()); |
1013 | 1013 |
1014 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */, | 1014 operation()->Remove(URLForPath(parent_dir_path), false /* recursive */, |
1015 RecordStatusCallback()); | 1015 RecordStatusCallback()); |
1016 MessageLoop::current()->RunAllPending(); | 1016 MessageLoop::current()->RunUntilIdle(); |
1017 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, | 1017 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, |
1018 status()); | 1018 status()); |
1019 EXPECT_TRUE(change_observer()->HasNoChange()); | 1019 EXPECT_TRUE(change_observer()->HasNoChange()); |
1020 } | 1020 } |
1021 | 1021 |
1022 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) { | 1022 TEST_F(LocalFileSystemOperationTest, TestRemoveSuccess) { |
1023 FilePath empty_dir_path(CreateUniqueDir()); | 1023 FilePath empty_dir_path(CreateUniqueDir()); |
1024 EXPECT_TRUE(DirectoryExists(empty_dir_path)); | 1024 EXPECT_TRUE(DirectoryExists(empty_dir_path)); |
1025 | 1025 |
1026 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */, | 1026 operation()->Remove(URLForPath(empty_dir_path), false /* recursive */, |
1027 RecordStatusCallback()); | 1027 RecordStatusCallback()); |
1028 MessageLoop::current()->RunAllPending(); | 1028 MessageLoop::current()->RunUntilIdle(); |
1029 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1029 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1030 EXPECT_FALSE(DirectoryExists(empty_dir_path)); | 1030 EXPECT_FALSE(DirectoryExists(empty_dir_path)); |
1031 | 1031 |
1032 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); | 1032 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); |
1033 EXPECT_TRUE(change_observer()->HasNoChange()); | 1033 EXPECT_TRUE(change_observer()->HasNoChange()); |
1034 | 1034 |
1035 // Removing a non-empty directory with recursive flag == true should be ok. | 1035 // Removing a non-empty directory with recursive flag == true should be ok. |
1036 // parent_dir | 1036 // parent_dir |
1037 // | | | 1037 // | | |
1038 // child_dir child_file | 1038 // child_dir child_file |
1039 // Verify deleting parent_dir. | 1039 // Verify deleting parent_dir. |
1040 FilePath parent_dir_path(CreateUniqueDir()); | 1040 FilePath parent_dir_path(CreateUniqueDir()); |
1041 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); | 1041 FilePath child_file_path(CreateUniqueFileInDir(parent_dir_path)); |
1042 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); | 1042 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); |
1043 ASSERT_FALSE(child_dir_path.empty()); | 1043 ASSERT_FALSE(child_dir_path.empty()); |
1044 | 1044 |
1045 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, | 1045 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, |
1046 RecordStatusCallback()); | 1046 RecordStatusCallback()); |
1047 MessageLoop::current()->RunAllPending(); | 1047 MessageLoop::current()->RunUntilIdle(); |
1048 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1048 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1049 EXPECT_FALSE(DirectoryExists(parent_dir_path)); | 1049 EXPECT_FALSE(DirectoryExists(parent_dir_path)); |
1050 | 1050 |
1051 // Remove is not a 'read' access. | 1051 // Remove is not a 'read' access. |
1052 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); | 1052 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count()); |
1053 | 1053 |
1054 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); | 1054 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); |
1055 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); | 1055 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); |
1056 EXPECT_TRUE(change_observer()->HasNoChange()); | 1056 EXPECT_TRUE(change_observer()->HasNoChange()); |
1057 } | 1057 } |
1058 | 1058 |
1059 TEST_F(LocalFileSystemOperationTest, TestTruncate) { | 1059 TEST_F(LocalFileSystemOperationTest, TestTruncate) { |
1060 FilePath dir_path(CreateUniqueDir()); | 1060 FilePath dir_path(CreateUniqueDir()); |
1061 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1061 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1062 | 1062 |
1063 char test_data[] = "test data"; | 1063 char test_data[] = "test data"; |
1064 int data_size = static_cast<int>(sizeof(test_data)); | 1064 int data_size = static_cast<int>(sizeof(test_data)); |
1065 EXPECT_EQ(data_size, | 1065 EXPECT_EQ(data_size, |
1066 file_util::WriteFile(PlatformPath(file_path), | 1066 file_util::WriteFile(PlatformPath(file_path), |
1067 test_data, data_size)); | 1067 test_data, data_size)); |
1068 | 1068 |
1069 // Check that its length is the size of the data written. | 1069 // Check that its length is the size of the data written. |
1070 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); | 1070 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); |
1071 MessageLoop::current()->RunAllPending(); | 1071 MessageLoop::current()->RunUntilIdle(); |
1072 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1072 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1073 EXPECT_FALSE(info().is_directory); | 1073 EXPECT_FALSE(info().is_directory); |
1074 EXPECT_EQ(data_size, info().size); | 1074 EXPECT_EQ(data_size, info().size); |
1075 | 1075 |
1076 // Extend the file by truncating it. | 1076 // Extend the file by truncating it. |
1077 int length = 17; | 1077 int length = 17; |
1078 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback()); | 1078 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback()); |
1079 MessageLoop::current()->RunAllPending(); | 1079 MessageLoop::current()->RunUntilIdle(); |
1080 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1080 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1081 | 1081 |
1082 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1082 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1083 EXPECT_TRUE(change_observer()->HasNoChange()); | 1083 EXPECT_TRUE(change_observer()->HasNoChange()); |
1084 | 1084 |
1085 // Check that its length is now 17 and that it's all zeroes after the test | 1085 // Check that its length is now 17 and that it's all zeroes after the test |
1086 // data. | 1086 // data. |
1087 base::PlatformFileInfo info; | 1087 base::PlatformFileInfo info; |
1088 | 1088 |
1089 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1089 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1090 EXPECT_EQ(length, info.size); | 1090 EXPECT_EQ(length, info.size); |
1091 char data[100]; | 1091 char data[100]; |
1092 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 1092 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
1093 for (int i = 0; i < length; ++i) { | 1093 for (int i = 0; i < length; ++i) { |
1094 if (i < static_cast<int>(sizeof(test_data))) | 1094 if (i < static_cast<int>(sizeof(test_data))) |
1095 EXPECT_EQ(test_data[i], data[i]); | 1095 EXPECT_EQ(test_data[i], data[i]); |
1096 else | 1096 else |
1097 EXPECT_EQ(0, data[i]); | 1097 EXPECT_EQ(0, data[i]); |
1098 } | 1098 } |
1099 | 1099 |
1100 // Shorten the file by truncating it. | 1100 // Shorten the file by truncating it. |
1101 length = 3; | 1101 length = 3; |
1102 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback()); | 1102 operation()->Truncate(URLForPath(file_path), length, RecordStatusCallback()); |
1103 MessageLoop::current()->RunAllPending(); | 1103 MessageLoop::current()->RunUntilIdle(); |
1104 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1104 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1105 | 1105 |
1106 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1106 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1107 EXPECT_TRUE(change_observer()->HasNoChange()); | 1107 EXPECT_TRUE(change_observer()->HasNoChange()); |
1108 | 1108 |
1109 // Check that its length is now 3 and that it contains only bits of test data. | 1109 // Check that its length is now 3 and that it contains only bits of test data. |
1110 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1110 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1111 EXPECT_EQ(length, info.size); | 1111 EXPECT_EQ(length, info.size); |
1112 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); | 1112 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); |
1113 for (int i = 0; i < length; ++i) | 1113 for (int i = 0; i < length; ++i) |
1114 EXPECT_EQ(test_data[i], data[i]); | 1114 EXPECT_EQ(test_data[i], data[i]); |
1115 | 1115 |
1116 // Truncate is not a 'read' access. (Here expected access count is 1 | 1116 // Truncate is not a 'read' access. (Here expected access count is 1 |
1117 // since we made 1 read access for GetMetadata.) | 1117 // since we made 1 read access for GetMetadata.) |
1118 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 1118 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
1119 } | 1119 } |
1120 | 1120 |
1121 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { | 1121 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { |
1122 base::PlatformFileInfo info; | 1122 base::PlatformFileInfo info; |
1123 | 1123 |
1124 FilePath dir_path(CreateUniqueDir()); | 1124 FilePath dir_path(CreateUniqueDir()); |
1125 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1125 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1126 | 1126 |
1127 GrantQuotaForCurrentUsage(); | 1127 GrantQuotaForCurrentUsage(); |
1128 AddQuota(10); | 1128 AddQuota(10); |
1129 | 1129 |
1130 operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback()); | 1130 operation()->Truncate(URLForPath(file_path), 10, RecordStatusCallback()); |
1131 MessageLoop::current()->RunAllPending(); | 1131 MessageLoop::current()->RunUntilIdle(); |
1132 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1132 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1133 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1133 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1134 EXPECT_TRUE(change_observer()->HasNoChange()); | 1134 EXPECT_TRUE(change_observer()->HasNoChange()); |
1135 | 1135 |
1136 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1136 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1137 EXPECT_EQ(10, info.size); | 1137 EXPECT_EQ(10, info.size); |
1138 | 1138 |
1139 operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback()); | 1139 operation()->Truncate(URLForPath(file_path), 11, RecordStatusCallback()); |
1140 MessageLoop::current()->RunAllPending(); | 1140 MessageLoop::current()->RunUntilIdle(); |
1141 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 1141 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
1142 EXPECT_TRUE(change_observer()->HasNoChange()); | 1142 EXPECT_TRUE(change_observer()->HasNoChange()); |
1143 | 1143 |
1144 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); | 1144 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); |
1145 EXPECT_EQ(10, info.size); | 1145 EXPECT_EQ(10, info.size); |
1146 } | 1146 } |
1147 | 1147 |
1148 TEST_F(LocalFileSystemOperationTest, TestTouchFile) { | 1148 TEST_F(LocalFileSystemOperationTest, TestTouchFile) { |
1149 FilePath file_path(CreateUniqueFileInDir(FilePath())); | 1149 FilePath file_path(CreateUniqueFileInDir(FilePath())); |
1150 FilePath platform_path = PlatformPath(file_path); | 1150 FilePath platform_path = PlatformPath(file_path); |
1151 | 1151 |
1152 base::PlatformFileInfo info; | 1152 base::PlatformFileInfo info; |
1153 | 1153 |
1154 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1154 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
1155 EXPECT_FALSE(info.is_directory); | 1155 EXPECT_FALSE(info.is_directory); |
1156 EXPECT_EQ(0, info.size); | 1156 EXPECT_EQ(0, info.size); |
1157 const base::Time last_modified = info.last_modified; | 1157 const base::Time last_modified = info.last_modified; |
1158 const base::Time last_accessed = info.last_accessed; | 1158 const base::Time last_accessed = info.last_accessed; |
1159 | 1159 |
1160 const base::Time new_modified_time = base::Time::UnixEpoch(); | 1160 const base::Time new_modified_time = base::Time::UnixEpoch(); |
1161 const base::Time new_accessed_time = new_modified_time + | 1161 const base::Time new_accessed_time = new_modified_time + |
1162 base::TimeDelta::FromHours(77); | 1162 base::TimeDelta::FromHours(77); |
1163 ASSERT_NE(last_modified, new_modified_time); | 1163 ASSERT_NE(last_modified, new_modified_time); |
1164 ASSERT_NE(last_accessed, new_accessed_time); | 1164 ASSERT_NE(last_accessed, new_accessed_time); |
1165 | 1165 |
1166 operation()->TouchFile( | 1166 operation()->TouchFile( |
1167 URLForPath(file_path), new_accessed_time, new_modified_time, | 1167 URLForPath(file_path), new_accessed_time, new_modified_time, |
1168 RecordStatusCallback()); | 1168 RecordStatusCallback()); |
1169 MessageLoop::current()->RunAllPending(); | 1169 MessageLoop::current()->RunUntilIdle(); |
1170 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1170 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1171 EXPECT_TRUE(change_observer()->HasNoChange()); | 1171 EXPECT_TRUE(change_observer()->HasNoChange()); |
1172 | 1172 |
1173 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); | 1173 EXPECT_TRUE(file_util::GetFileInfo(platform_path, &info)); |
1174 // We compare as time_t here to lower our resolution, to avoid false | 1174 // We compare as time_t here to lower our resolution, to avoid false |
1175 // negatives caused by conversion to the local filesystem's native | 1175 // negatives caused by conversion to the local filesystem's native |
1176 // representation and back. | 1176 // representation and back. |
1177 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); | 1177 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); |
1178 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); | 1178 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); |
1179 } | 1179 } |
1180 | 1180 |
1181 TEST_F(LocalFileSystemOperationTest, TestCreateSnapshotFile) { | 1181 TEST_F(LocalFileSystemOperationTest, TestCreateSnapshotFile) { |
1182 FilePath dir_path(CreateUniqueDir()); | 1182 FilePath dir_path(CreateUniqueDir()); |
1183 | 1183 |
1184 // Create a file for the testing. | 1184 // Create a file for the testing. |
1185 operation()->DirectoryExists(URLForPath(dir_path), | 1185 operation()->DirectoryExists(URLForPath(dir_path), |
1186 RecordStatusCallback()); | 1186 RecordStatusCallback()); |
1187 FilePath file_path(CreateUniqueFileInDir(dir_path)); | 1187 FilePath file_path(CreateUniqueFileInDir(dir_path)); |
1188 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); | 1188 operation()->FileExists(URLForPath(file_path), RecordStatusCallback()); |
1189 MessageLoop::current()->RunAllPending(); | 1189 MessageLoop::current()->RunUntilIdle(); |
1190 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1190 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1191 | 1191 |
1192 // See if we can get a 'snapshot' file info for the file. | 1192 // See if we can get a 'snapshot' file info for the file. |
1193 // Since LocalFileSystemOperation assumes the file exists in the local | 1193 // Since LocalFileSystemOperation assumes the file exists in the local |
1194 // directory it should just returns the same metadata and platform_path | 1194 // directory it should just returns the same metadata and platform_path |
1195 // as the file itself. | 1195 // as the file itself. |
1196 operation()->CreateSnapshotFile(URLForPath(file_path), | 1196 operation()->CreateSnapshotFile(URLForPath(file_path), |
1197 RecordSnapshotFileCallback()); | 1197 RecordSnapshotFileCallback()); |
1198 MessageLoop::current()->RunAllPending(); | 1198 MessageLoop::current()->RunUntilIdle(); |
1199 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 1199 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
1200 EXPECT_FALSE(info().is_directory); | 1200 EXPECT_FALSE(info().is_directory); |
1201 EXPECT_EQ(PlatformPath(file_path), path()); | 1201 EXPECT_EQ(PlatformPath(file_path), path()); |
1202 EXPECT_TRUE(change_observer()->HasNoChange()); | 1202 EXPECT_TRUE(change_observer()->HasNoChange()); |
1203 | 1203 |
1204 // The FileSystemOpration implementation does not create a | 1204 // The FileSystemOpration implementation does not create a |
1205 // shareable file reference. | 1205 // shareable file reference. |
1206 EXPECT_EQ(NULL, shareable_file_ref()); | 1206 EXPECT_EQ(NULL, shareable_file_ref()); |
1207 } | 1207 } |
1208 | 1208 |
1209 } // namespace fileapi | 1209 } // namespace fileapi |
OLD | NEW |