| 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/file_system/copy_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
| 9 #include "chrome/browser/chromeos/drive/file_cache.h" | 9 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 10 #include "chrome/browser/chromeos/drive/file_change.h" | 10 #include "chrome/browser/chromeos/drive/file_change.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 TEST_F(CopyOperationTest, | 119 TEST_F(CopyOperationTest, |
| 120 TransferFileFromLocalToRemote_ExistingHostedDocument) { | 120 TransferFileFromLocalToRemote_ExistingHostedDocument) { |
| 121 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); | 121 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); |
| 122 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( | 122 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( |
| 123 "drive/root/Directory 1/copied.gdoc")); | 123 "drive/root/Directory 1/copied.gdoc")); |
| 124 | 124 |
| 125 // Prepare a local file, which is a json file of a hosted document, which | 125 // Prepare a local file, which is a json file of a hosted document, which |
| 126 // matches "drive/root/Document 1 excludeDir-test". | 126 // matches "drive/root/Document 1 excludeDir-test". |
| 127 ASSERT_TRUE(util::CreateGDocFile( | 127 ASSERT_TRUE(util::CreateGDocFile( |
| 128 local_src_path, | 128 local_src_path, |
| 129 GURL("https://3_document_self_link/document:5_document_resource_id"), | 129 GURL("https://3_document_self_link/5_document_resource_id"), |
| 130 "document:5_document_resource_id")); | 130 "5_document_resource_id")); |
| 131 | 131 |
| 132 ResourceEntry entry; | 132 ResourceEntry entry; |
| 133 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 133 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 134 GetLocalResourceEntry(remote_dest_path, &entry)); | 134 GetLocalResourceEntry(remote_dest_path, &entry)); |
| 135 | 135 |
| 136 // Transfer the local file to Drive. | 136 // Transfer the local file to Drive. |
| 137 FileError error = FILE_ERROR_FAILED; | 137 FileError error = FILE_ERROR_FAILED; |
| 138 operation_->TransferFileFromLocalToRemote( | 138 operation_->TransferFileFromLocalToRemote( |
| 139 local_src_path, | 139 local_src_path, |
| 140 remote_dest_path, | 140 remote_dest_path, |
| 141 google_apis::test_util::CreateCopyResultCallback(&error)); | 141 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 142 content::RunAllBlockingPoolTasksUntilIdle(); | 142 content::RunAllBlockingPoolTasksUntilIdle(); |
| 143 EXPECT_EQ(FILE_ERROR_OK, error); | 143 EXPECT_EQ(FILE_ERROR_OK, error); |
| 144 | 144 |
| 145 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 145 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
| 146 | 146 |
| 147 EXPECT_EQ(1U, delegate()->get_changed_files().size()); | 147 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
| 148 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path)); | 148 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path)); |
| 149 // New copy is created. | 149 // New copy is created. |
| 150 EXPECT_NE("document:5_document_resource_id", entry.resource_id()); | 150 EXPECT_NE("5_document_resource_id", entry.resource_id()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_OrphanHostedDocument) { | 153 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_OrphanHostedDocument) { |
| 154 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); | 154 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); |
| 155 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( | 155 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( |
| 156 "drive/root/Directory 1/moved.gdoc")); | 156 "drive/root/Directory 1/moved.gdoc")); |
| 157 | 157 |
| 158 // Prepare a local file, which is a json file of a hosted document, which | 158 // Prepare a local file, which is a json file of a hosted document, which |
| 159 // matches "drive/other/Orphan Document". | 159 // matches "drive/other/Orphan Document". |
| 160 ASSERT_TRUE(util::CreateGDocFile( | 160 ASSERT_TRUE(util::CreateGDocFile( |
| 161 local_src_path, | 161 local_src_path, |
| 162 GURL("https://3_document_self_link/document:orphan_doc_1"), | 162 GURL("https://3_document_self_link/orphan_doc_1"), |
| 163 "document:orphan_doc_1")); | 163 "orphan_doc_1")); |
| 164 | 164 |
| 165 ResourceEntry entry; | 165 ResourceEntry entry; |
| 166 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 166 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 167 GetLocalResourceEntry(remote_dest_path, &entry)); | 167 GetLocalResourceEntry(remote_dest_path, &entry)); |
| 168 | 168 |
| 169 // Transfer the local file to Drive. | 169 // Transfer the local file to Drive. |
| 170 FileError error = FILE_ERROR_FAILED; | 170 FileError error = FILE_ERROR_FAILED; |
| 171 operation_->TransferFileFromLocalToRemote( | 171 operation_->TransferFileFromLocalToRemote( |
| 172 local_src_path, | 172 local_src_path, |
| 173 remote_dest_path, | 173 remote_dest_path, |
| 174 google_apis::test_util::CreateCopyResultCallback(&error)); | 174 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 175 content::RunAllBlockingPoolTasksUntilIdle(); | 175 content::RunAllBlockingPoolTasksUntilIdle(); |
| 176 EXPECT_EQ(FILE_ERROR_OK, error); | 176 EXPECT_EQ(FILE_ERROR_OK, error); |
| 177 | 177 |
| 178 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 178 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
| 179 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); | 179 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); |
| 180 EXPECT_TRUE(delegate()->updated_local_ids().count(entry.local_id())); | 180 EXPECT_TRUE(delegate()->updated_local_ids().count(entry.local_id())); |
| 181 | 181 |
| 182 EXPECT_EQ(1U, delegate()->get_changed_files().size()); | 182 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
| 183 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path)); | 183 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path)); |
| 184 // The original document got new parent. | 184 // The original document got new parent. |
| 185 EXPECT_EQ("document:orphan_doc_1", entry.resource_id()); | 185 EXPECT_EQ("orphan_doc_1", entry.resource_id()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) { | 188 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) { |
| 189 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); | 189 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); |
| 190 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( | 190 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( |
| 191 "drive/root/Directory 1/moved.gdoc")); | 191 "drive/root/Directory 1/moved.gdoc")); |
| 192 | 192 |
| 193 // Create a hosted document on the server that is not synced to local yet. | 193 // Create a hosted document on the server that is not synced to local yet. |
| 194 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 194 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; |
| 195 scoped_ptr<google_apis::FileResource> new_gdoc_entry; | 195 scoped_ptr<google_apis::FileResource> new_gdoc_entry; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 pending_callback.Run(FILE_ERROR_OK); | 514 pending_callback.Run(FILE_ERROR_OK); |
| 515 content::RunAllBlockingPoolTasksUntilIdle(); | 515 content::RunAllBlockingPoolTasksUntilIdle(); |
| 516 | 516 |
| 517 EXPECT_EQ(FILE_ERROR_OK, copy_error); | 517 EXPECT_EQ(FILE_ERROR_OK, copy_error); |
| 518 ResourceEntry entry; | 518 ResourceEntry entry; |
| 519 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry)); | 519 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry)); |
| 520 } | 520 } |
| 521 | 521 |
| 522 } // namespace file_system | 522 } // namespace file_system |
| 523 } // namespace drive | 523 } // namespace drive |
| OLD | NEW |