| 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 "base/task_runner_util.h" |
| 8 #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" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 10 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 10 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); | 42 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); |
| 43 const std::string resource_id = entry.resource_id(); | 43 const std::string resource_id = entry.resource_id(); |
| 44 | 44 |
| 45 performer.Remove(entry.local_id(), | 45 performer.Remove(entry.local_id(), |
| 46 ClientContext(USER_INITIATED), | 46 ClientContext(USER_INITIATED), |
| 47 google_apis::test_util::CreateCopyResultCallback(&error)); | 47 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 48 content::RunAllBlockingPoolTasksUntilIdle(); | 48 content::RunAllBlockingPoolTasksUntilIdle(); |
| 49 EXPECT_EQ(FILE_ERROR_OK, error); | 49 EXPECT_EQ(FILE_ERROR_OK, error); |
| 50 | 50 |
| 51 // Verify the file is indeed removed in the server. | 51 // Verify the file is indeed removed in the server. |
| 52 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 52 google_apis::DriveApiErrorCode gdata_error = google_apis::DRIVE_OTHER_ERROR; |
| 53 scoped_ptr<google_apis::FileResource> gdata_entry; | 53 scoped_ptr<google_apis::FileResource> gdata_entry; |
| 54 fake_service()->GetFileResource( | 54 fake_service()->GetFileResource( |
| 55 resource_id, | 55 resource_id, |
| 56 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 56 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 57 &gdata_entry)); | 57 &gdata_entry)); |
| 58 content::RunAllBlockingPoolTasksUntilIdle(); | 58 content::RunAllBlockingPoolTasksUntilIdle(); |
| 59 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | 59 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
| 60 EXPECT_TRUE(gdata_entry->labels().is_trashed()); | 60 EXPECT_TRUE(gdata_entry->labels().is_trashed()); |
| 61 | 61 |
| 62 // Try removing non-existing file. | 62 // Try removing non-existing file. |
| 63 error = FILE_ERROR_FAILED; | 63 error = FILE_ERROR_FAILED; |
| 64 performer.Remove("non-existing-id", | 64 performer.Remove("non-existing-id", |
| 65 ClientContext(USER_INITIATED), | 65 ClientContext(USER_INITIATED), |
| 66 google_apis::test_util::CreateCopyResultCallback(&error)); | 66 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 67 content::RunAllBlockingPoolTasksUntilIdle(); | 67 content::RunAllBlockingPoolTasksUntilIdle(); |
| 68 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 68 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(RemovePerformerTest, RemoveShared) { | 71 TEST_F(RemovePerformerTest, RemoveShared) { |
| 72 RemovePerformer performer(blocking_task_runner(), delegate(), scheduler(), | 72 RemovePerformer performer(blocking_task_runner(), delegate(), scheduler(), |
| 73 metadata()); | 73 metadata()); |
| 74 | 74 |
| 75 const base::FilePath kPathInMyDrive(FILE_PATH_LITERAL( | 75 const base::FilePath kPathInMyDrive(FILE_PATH_LITERAL( |
| 76 "drive/root/shared.txt")); | 76 "drive/root/shared.txt")); |
| 77 const base::FilePath kPathInOther(FILE_PATH_LITERAL( | 77 const base::FilePath kPathInOther(FILE_PATH_LITERAL( |
| 78 "drive/other/shared.txt")); | 78 "drive/other/shared.txt")); |
| 79 | 79 |
| 80 // Prepare a shared file to the root folder. | 80 // Prepare a shared file to the root folder. |
| 81 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 81 google_apis::DriveApiErrorCode gdata_error = google_apis::DRIVE_OTHER_ERROR; |
| 82 scoped_ptr<google_apis::FileResource> gdata_entry; | 82 scoped_ptr<google_apis::FileResource> gdata_entry; |
| 83 fake_service()->AddNewFile( | 83 fake_service()->AddNewFile( |
| 84 "text/plain", | 84 "text/plain", |
| 85 "dummy content", | 85 "dummy content", |
| 86 fake_service()->GetRootResourceId(), | 86 fake_service()->GetRootResourceId(), |
| 87 kPathInMyDrive.BaseName().AsUTF8Unsafe(), | 87 kPathInMyDrive.BaseName().AsUTF8Unsafe(), |
| 88 true, // shared_with_me, | 88 true, // shared_with_me, |
| 89 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 89 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 90 &gdata_entry)); | 90 &gdata_entry)); |
| 91 content::RunAllBlockingPoolTasksUntilIdle(); | 91 content::RunAllBlockingPoolTasksUntilIdle(); |
| 92 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); | 92 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); |
| 93 CheckForUpdates(); | 93 CheckForUpdates(); |
| 94 | 94 |
| 95 // Remove it. Locally, the file should be moved to drive/other. | 95 // Remove it. Locally, the file should be moved to drive/other. |
| 96 ResourceEntry entry; | 96 ResourceEntry entry; |
| 97 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInMyDrive, &entry)); | 97 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInMyDrive, &entry)); |
| 98 FileError error = FILE_ERROR_FAILED; | 98 FileError error = FILE_ERROR_FAILED; |
| 99 performer.Remove(entry.local_id(), | 99 performer.Remove(entry.local_id(), |
| 100 ClientContext(USER_INITIATED), | 100 ClientContext(USER_INITIATED), |
| 101 google_apis::test_util::CreateCopyResultCallback(&error)); | 101 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 102 content::RunAllBlockingPoolTasksUntilIdle(); | 102 content::RunAllBlockingPoolTasksUntilIdle(); |
| 103 EXPECT_EQ(FILE_ERROR_OK, error); | 103 EXPECT_EQ(FILE_ERROR_OK, error); |
| 104 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 104 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 105 GetLocalResourceEntry(kPathInMyDrive, &entry)); | 105 GetLocalResourceEntry(kPathInMyDrive, &entry)); |
| 106 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry)); | 106 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry)); |
| 107 | 107 |
| 108 // Remotely, the entry should have lost its parent. | 108 // Remotely, the entry should have lost its parent. |
| 109 gdata_error = google_apis::GDATA_OTHER_ERROR; | 109 gdata_error = google_apis::DRIVE_OTHER_ERROR; |
| 110 const std::string resource_id = gdata_entry->file_id(); | 110 const std::string resource_id = gdata_entry->file_id(); |
| 111 fake_service()->GetFileResource( | 111 fake_service()->GetFileResource( |
| 112 resource_id, | 112 resource_id, |
| 113 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 113 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
| 114 &gdata_entry)); | 114 &gdata_entry)); |
| 115 content::RunAllBlockingPoolTasksUntilIdle(); | 115 content::RunAllBlockingPoolTasksUntilIdle(); |
| 116 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | 116 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
| 117 EXPECT_FALSE(gdata_entry->labels().is_trashed()); // It's not deleted. | 117 EXPECT_FALSE(gdata_entry->labels().is_trashed()); // It's not deleted. |
| 118 EXPECT_TRUE(gdata_entry->parents().empty()); | 118 EXPECT_TRUE(gdata_entry->parents().empty()); |
| 119 } | 119 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); | 190 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); |
| 191 EXPECT_EQ(src_entry.parent_local_id(), result_entry.parent_local_id()); | 191 EXPECT_EQ(src_entry.parent_local_id(), result_entry.parent_local_id()); |
| 192 | 192 |
| 193 ASSERT_EQ(1U, delegate()->drive_sync_errors().size()); | 193 ASSERT_EQ(1U, delegate()->drive_sync_errors().size()); |
| 194 EXPECT_EQ(file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION, | 194 EXPECT_EQ(file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION, |
| 195 delegate()->drive_sync_errors()[0]); | 195 delegate()->drive_sync_errors()[0]); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace internal | 198 } // namespace internal |
| 199 } // namespace drive | 199 } // namespace drive |
| OLD | NEW |