| 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/remove_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/remove_performer.h" |
| 6 | 6 |
| 7 #include "base/task_runner_util.h" |
| 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 8 #include "chrome/browser/drive/fake_drive_service.h" | 11 #include "chrome/browser/drive/fake_drive_service.h" |
| 9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 12 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 10 #include "chrome/browser/google_apis/test_util.h" | 13 #include "chrome/browser/google_apis/test_util.h" |
| 11 | 14 |
| 12 namespace drive { | 15 namespace drive { |
| 13 namespace internal { | 16 namespace internal { |
| 14 | 17 |
| 15 typedef file_system::OperationTestBase RemovePerformerTest; | 18 typedef file_system::OperationTestBase RemovePerformerTest; |
| 16 | 19 |
| 17 TEST_F(RemovePerformerTest, RemoveFile) { | 20 TEST_F(RemovePerformerTest, RemoveFile) { |
| 18 RemovePerformer performer(blocking_task_runner(), scheduler(), metadata()); | 21 RemovePerformer performer(blocking_task_runner(), scheduler(), metadata()); |
| 19 | 22 |
| 20 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 23 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 21 base::FilePath file_in_subdir( | |
| 22 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 23 | 24 |
| 24 // Remove a file in root. | 25 // Mark the file as deleted. |
| 26 FileError error = FILE_ERROR_FAILED; |
| 25 ResourceEntry entry; | 27 ResourceEntry entry; |
| 26 FileError error = FILE_ERROR_FAILED; | |
| 27 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); | 28 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); |
| 29 entry.set_parent_local_id(util::kDriveOtherDirLocalId); |
| 30 entry.set_deleted(true); |
| 31 base::PostTaskAndReplyWithResult( |
| 32 blocking_task_runner(), |
| 33 FROM_HERE, |
| 34 base::Bind(&ResourceMetadata::RefreshEntry, |
| 35 base::Unretained(metadata()), |
| 36 entry), |
| 37 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 38 test_util::RunBlockingPoolTask(); |
| 39 EXPECT_EQ(FILE_ERROR_OK, error); |
| 40 |
| 41 // Remove the file. |
| 28 performer.Remove(entry.local_id(), | 42 performer.Remove(entry.local_id(), |
| 29 google_apis::test_util::CreateCopyResultCallback(&error)); | 43 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 30 test_util::RunBlockingPoolTask(); | 44 test_util::RunBlockingPoolTask(); |
| 31 EXPECT_EQ(FILE_ERROR_OK, error); | 45 EXPECT_EQ(FILE_ERROR_OK, error); |
| 32 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); | 46 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); |
| 33 | 47 |
| 34 // Remove a file in subdirectory. | |
| 35 error = FILE_ERROR_FAILED; | |
| 36 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); | |
| 37 const std::string resource_id = entry.resource_id(); | |
| 38 | |
| 39 performer.Remove(entry.local_id(), | |
| 40 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 41 test_util::RunBlockingPoolTask(); | |
| 42 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 43 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
| 44 GetLocalResourceEntry(file_in_subdir, &entry)); | |
| 45 | |
| 46 // Verify the file is indeed removed in the server. | 48 // Verify the file is indeed removed in the server. |
| 47 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 49 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; |
| 48 scoped_ptr<google_apis::ResourceEntry> gdata_entry; | 50 scoped_ptr<google_apis::ResourceEntry> gdata_entry; |
| 49 fake_service()->GetResourceEntry( | 51 fake_service()->GetResourceEntry( |
| 50 resource_id, | 52 entry.resource_id(), |
| 51 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 53 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 52 &gdata_entry)); | 54 &gdata_entry)); |
| 53 test_util::RunBlockingPoolTask(); | 55 test_util::RunBlockingPoolTask(); |
| 54 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | 56 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
| 55 EXPECT_TRUE(gdata_entry->deleted()); | 57 EXPECT_TRUE(gdata_entry->deleted()); |
| 56 | 58 |
| 57 // Try removing non-existing file. | 59 // Try removing non-existing file. |
| 58 error = FILE_ERROR_FAILED; | 60 error = FILE_ERROR_FAILED; |
| 59 performer.Remove("non-existing-id", | 61 performer.Remove("non-existing-id", |
| 60 google_apis::test_util::CreateCopyResultCallback(&error)); | 62 google_apis::test_util::CreateCopyResultCallback(&error)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 78 "dummy content", | 80 "dummy content", |
| 79 fake_service()->GetRootResourceId(), | 81 fake_service()->GetRootResourceId(), |
| 80 kPathInMyDrive.BaseName().AsUTF8Unsafe(), | 82 kPathInMyDrive.BaseName().AsUTF8Unsafe(), |
| 81 true, // shared_with_me, | 83 true, // shared_with_me, |
| 82 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 84 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 83 &gdata_entry)); | 85 &gdata_entry)); |
| 84 test_util::RunBlockingPoolTask(); | 86 test_util::RunBlockingPoolTask(); |
| 85 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); | 87 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); |
| 86 CheckForUpdates(); | 88 CheckForUpdates(); |
| 87 | 89 |
| 88 // Remove it. Locally, the file should be moved to drive/other. | 90 // Mark the file as deleted. |
| 91 FileError error = FILE_ERROR_FAILED; |
| 89 ResourceEntry entry; | 92 ResourceEntry entry; |
| 90 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInMyDrive, &entry)); | 93 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInMyDrive, &entry)); |
| 91 FileError error = FILE_ERROR_FAILED; | 94 entry.set_parent_local_id(util::kDriveOtherDirLocalId); |
| 95 entry.set_deleted(true); |
| 96 base::PostTaskAndReplyWithResult( |
| 97 blocking_task_runner(), |
| 98 FROM_HERE, |
| 99 base::Bind(&ResourceMetadata::RefreshEntry, |
| 100 base::Unretained(metadata()), |
| 101 entry), |
| 102 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 103 test_util::RunBlockingPoolTask(); |
| 104 EXPECT_EQ(FILE_ERROR_OK, error); |
| 105 |
| 106 // Remove it. Locally, the file should be moved to drive/other. |
| 92 performer.Remove(entry.local_id(), | 107 performer.Remove(entry.local_id(), |
| 93 google_apis::test_util::CreateCopyResultCallback(&error)); | 108 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 94 test_util::RunBlockingPoolTask(); | 109 test_util::RunBlockingPoolTask(); |
| 95 EXPECT_EQ(FILE_ERROR_OK, error); | 110 EXPECT_EQ(FILE_ERROR_OK, error); |
| 96 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 97 GetLocalResourceEntry(kPathInMyDrive, &entry)); | 112 GetLocalResourceEntry(kPathInMyDrive, &entry)); |
| 98 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry)); | 113 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry)); |
| 99 | 114 |
| 100 // Remotely, the entry should have lost its parent. | 115 // Remotely, the entry should have lost its parent. |
| 101 gdata_error = google_apis::GDATA_OTHER_ERROR; | 116 gdata_error = google_apis::GDATA_OTHER_ERROR; |
| 102 const std::string resource_id = gdata_entry->resource_id(); | 117 const std::string resource_id = gdata_entry->resource_id(); |
| 103 fake_service()->GetResourceEntry( | 118 fake_service()->GetResourceEntry( |
| 104 resource_id, | 119 resource_id, |
| 105 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 120 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 106 &gdata_entry)); | 121 &gdata_entry)); |
| 107 test_util::RunBlockingPoolTask(); | 122 test_util::RunBlockingPoolTask(); |
| 108 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | 123 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
| 109 EXPECT_FALSE(gdata_entry->deleted()); // It's not deleted. | 124 EXPECT_FALSE(gdata_entry->deleted()); // It's not deleted. |
| 110 EXPECT_FALSE(gdata_entry->GetLinkByType(google_apis::Link::LINK_PARENT)); | 125 EXPECT_FALSE(gdata_entry->GetLinkByType(google_apis::Link::LINK_PARENT)); |
| 111 } | 126 } |
| 112 | 127 |
| 113 } // namespace internal | 128 } // namespace internal |
| 114 } // namespace drive | 129 } // namespace drive |
| OLD | NEW |