OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/drive/sync/entry_update_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 fake_service()->GetResourceEntry( | 422 fake_service()->GetResourceEntry( |
423 entry.resource_id(), | 423 entry.resource_id(), |
424 google_apis::test_util::CreateCopyResultCallback(&status, | 424 google_apis::test_util::CreateCopyResultCallback(&status, |
425 &resource_entry)); | 425 &resource_entry)); |
426 test_util::RunBlockingPoolTask(); | 426 test_util::RunBlockingPoolTask(); |
427 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | 427 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
428 ASSERT_TRUE(resource_entry); | 428 ASSERT_TRUE(resource_entry); |
429 EXPECT_FALSE(resource_entry->is_folder()); | 429 EXPECT_FALSE(resource_entry->is_folder()); |
430 } | 430 } |
431 | 431 |
| 432 TEST_F(EntryUpdatePerformerTest, UpdateEntry_NewFileOpendForWrite) { |
| 433 // Create a new file locally. |
| 434 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); |
| 435 |
| 436 ResourceEntry parent; |
| 437 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath.DirName(), &parent)); |
| 438 |
| 439 ResourceEntry entry; |
| 440 entry.set_parent_local_id(parent.local_id()); |
| 441 entry.set_title(kFilePath.BaseName().AsUTF8Unsafe()); |
| 442 entry.mutable_file_specific_info()->set_content_mime_type("text/plain"); |
| 443 entry.set_metadata_edit_state(ResourceEntry::DIRTY); |
| 444 |
| 445 FileError error = FILE_ERROR_FAILED; |
| 446 std::string local_id; |
| 447 base::PostTaskAndReplyWithResult( |
| 448 blocking_task_runner(), |
| 449 FROM_HERE, |
| 450 base::Bind(&internal::ResourceMetadata::AddEntry, |
| 451 base::Unretained(metadata()), |
| 452 entry, |
| 453 &local_id), |
| 454 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 455 test_util::RunBlockingPoolTask(); |
| 456 EXPECT_EQ(FILE_ERROR_OK, error); |
| 457 |
| 458 const std::string kTestFileContent = "This is a new file."; |
| 459 EXPECT_EQ(FILE_ERROR_OK, StoreAndMarkDirty(local_id, kTestFileContent)); |
| 460 |
| 461 // Emulate a situation where someone is writing to the file. |
| 462 scoped_ptr<base::ScopedClosureRunner> file_closer; |
| 463 error = FILE_ERROR_FAILED; |
| 464 base::PostTaskAndReplyWithResult( |
| 465 blocking_task_runner(), |
| 466 FROM_HERE, |
| 467 base::Bind(&FileCache::OpenForWrite, |
| 468 base::Unretained(cache()), |
| 469 local_id, |
| 470 &file_closer), |
| 471 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 472 test_util::RunBlockingPoolTask(); |
| 473 EXPECT_EQ(FILE_ERROR_OK, error); |
| 474 |
| 475 // Update, but no update is performed because the file is opened. |
| 476 error = FILE_ERROR_FAILED; |
| 477 performer_->UpdateEntry( |
| 478 local_id, |
| 479 ClientContext(USER_INITIATED), |
| 480 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 481 test_util::RunBlockingPoolTask(); |
| 482 EXPECT_EQ(FILE_ERROR_OK, error); |
| 483 |
| 484 // The entry hasn't got a resource ID yet. |
| 485 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); |
| 486 EXPECT_TRUE(entry.resource_id().empty()); |
| 487 |
| 488 // Close the file. |
| 489 file_closer.reset(); |
| 490 |
| 491 // Update. This should result in creating a new file on the server. |
| 492 error = FILE_ERROR_FAILED; |
| 493 performer_->UpdateEntry( |
| 494 local_id, |
| 495 ClientContext(USER_INITIATED), |
| 496 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 497 test_util::RunBlockingPoolTask(); |
| 498 EXPECT_EQ(FILE_ERROR_OK, error); |
| 499 |
| 500 // The entry got a resource ID. |
| 501 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); |
| 502 EXPECT_FALSE(entry.resource_id().empty()); |
| 503 EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state()); |
| 504 } |
| 505 |
432 TEST_F(EntryUpdatePerformerTest, UpdateEntry_CreateDirectory) { | 506 TEST_F(EntryUpdatePerformerTest, UpdateEntry_CreateDirectory) { |
433 // Create a new directory locally. | 507 // Create a new directory locally. |
434 const base::FilePath kPath(FILE_PATH_LITERAL("drive/root/New Directory")); | 508 const base::FilePath kPath(FILE_PATH_LITERAL("drive/root/New Directory")); |
435 | 509 |
436 ResourceEntry parent; | 510 ResourceEntry parent; |
437 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPath.DirName(), &parent)); | 511 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPath.DirName(), &parent)); |
438 | 512 |
439 ResourceEntry entry; | 513 ResourceEntry entry; |
440 entry.set_parent_local_id(parent.local_id()); | 514 entry.set_parent_local_id(parent.local_id()); |
441 entry.set_title(kPath.BaseName().AsUTF8Unsafe()); | 515 entry.set_title(kPath.BaseName().AsUTF8Unsafe()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 google_apis::test_util::CreateCopyResultCallback(&status, | 551 google_apis::test_util::CreateCopyResultCallback(&status, |
478 &resource_entry)); | 552 &resource_entry)); |
479 test_util::RunBlockingPoolTask(); | 553 test_util::RunBlockingPoolTask(); |
480 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | 554 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
481 ASSERT_TRUE(resource_entry); | 555 ASSERT_TRUE(resource_entry); |
482 EXPECT_TRUE(resource_entry->is_folder()); | 556 EXPECT_TRUE(resource_entry->is_folder()); |
483 } | 557 } |
484 | 558 |
485 } // namespace internal | 559 } // namespace internal |
486 } // namespace drive | 560 } // namespace drive |
OLD | NEW |