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" |
11 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 11 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
12 #include "chrome/browser/chromeos/drive/file_system_util.h" | 12 #include "chrome/browser/chromeos/drive/file_system_util.h" |
13 #include "chrome/browser/drive/drive_api_util.h" | 13 #include "chrome/browser/drive/drive_api_util.h" |
14 #include "chrome/browser/drive/fake_drive_service.h" | 14 #include "chrome/browser/drive/fake_drive_service.h" |
| 15 #include "content/public/test/test_utils.h" |
15 #include "google_apis/drive/drive_api_parser.h" | 16 #include "google_apis/drive/drive_api_parser.h" |
16 #include "google_apis/drive/test_util.h" | 17 #include "google_apis/drive/test_util.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace drive { | 20 namespace drive { |
20 namespace file_system { | 21 namespace file_system { |
21 | 22 |
22 class CopyOperationTest : public OperationTestBase { | 23 class CopyOperationTest : public OperationTestBase { |
23 protected: | 24 protected: |
24 virtual void SetUp() OVERRIDE { | 25 virtual void SetUp() OVERRIDE { |
(...skipping 22 matching lines...) Expand all Loading... |
47 ResourceEntry entry; | 48 ResourceEntry entry; |
48 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 49 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
49 GetLocalResourceEntry(remote_dest_path, &entry)); | 50 GetLocalResourceEntry(remote_dest_path, &entry)); |
50 | 51 |
51 // Transfer the local file to Drive. | 52 // Transfer the local file to Drive. |
52 FileError error = FILE_ERROR_FAILED; | 53 FileError error = FILE_ERROR_FAILED; |
53 operation_->TransferFileFromLocalToRemote( | 54 operation_->TransferFileFromLocalToRemote( |
54 local_src_path, | 55 local_src_path, |
55 remote_dest_path, | 56 remote_dest_path, |
56 google_apis::test_util::CreateCopyResultCallback(&error)); | 57 google_apis::test_util::CreateCopyResultCallback(&error)); |
57 test_util::RunBlockingPoolTask(); | 58 content::RunAllBlockingPoolTasksUntilIdle(); |
58 EXPECT_EQ(FILE_ERROR_OK, error); | 59 EXPECT_EQ(FILE_ERROR_OK, error); |
59 | 60 |
60 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, | 61 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, |
61 // marks it dirty and requests the observer to upload the file. | 62 // marks it dirty and requests the observer to upload the file. |
62 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 63 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
63 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); | 64 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); |
64 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); | 65 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); |
65 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); | 66 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); |
66 | 67 |
67 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 68 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
(...skipping 11 matching lines...) Expand all Loading... |
79 // Confirm that the remote file exists. | 80 // Confirm that the remote file exists. |
80 ResourceEntry entry; | 81 ResourceEntry entry; |
81 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 82 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
82 | 83 |
83 // Transfer the local file to Drive. | 84 // Transfer the local file to Drive. |
84 FileError error = FILE_ERROR_FAILED; | 85 FileError error = FILE_ERROR_FAILED; |
85 operation_->TransferFileFromLocalToRemote( | 86 operation_->TransferFileFromLocalToRemote( |
86 local_src_path, | 87 local_src_path, |
87 remote_dest_path, | 88 remote_dest_path, |
88 google_apis::test_util::CreateCopyResultCallback(&error)); | 89 google_apis::test_util::CreateCopyResultCallback(&error)); |
89 test_util::RunBlockingPoolTask(); | 90 content::RunAllBlockingPoolTasksUntilIdle(); |
90 EXPECT_EQ(FILE_ERROR_OK, error); | 91 EXPECT_EQ(FILE_ERROR_OK, error); |
91 | 92 |
92 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, | 93 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, |
93 // marks it dirty and requests the observer to upload the file. | 94 // marks it dirty and requests the observer to upload the file. |
94 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 95 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
95 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); | 96 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); |
96 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); | 97 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); |
97 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); | 98 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); |
98 | 99 |
99 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 100 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
(...skipping 16 matching lines...) Expand all Loading... |
116 ResourceEntry entry; | 117 ResourceEntry entry; |
117 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 118 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
118 GetLocalResourceEntry(remote_dest_path, &entry)); | 119 GetLocalResourceEntry(remote_dest_path, &entry)); |
119 | 120 |
120 // Transfer the local file to Drive. | 121 // Transfer the local file to Drive. |
121 FileError error = FILE_ERROR_FAILED; | 122 FileError error = FILE_ERROR_FAILED; |
122 operation_->TransferFileFromLocalToRemote( | 123 operation_->TransferFileFromLocalToRemote( |
123 local_src_path, | 124 local_src_path, |
124 remote_dest_path, | 125 remote_dest_path, |
125 google_apis::test_util::CreateCopyResultCallback(&error)); | 126 google_apis::test_util::CreateCopyResultCallback(&error)); |
126 test_util::RunBlockingPoolTask(); | 127 content::RunAllBlockingPoolTasksUntilIdle(); |
127 EXPECT_EQ(FILE_ERROR_OK, error); | 128 EXPECT_EQ(FILE_ERROR_OK, error); |
128 | 129 |
129 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 130 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
130 | 131 |
131 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 132 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
132 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); | 133 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); |
133 // New copy is created. | 134 // New copy is created. |
134 EXPECT_NE("document:5_document_resource_id", entry.resource_id()); | 135 EXPECT_NE("document:5_document_resource_id", entry.resource_id()); |
135 } | 136 } |
136 | 137 |
(...skipping 12 matching lines...) Expand all Loading... |
149 ResourceEntry entry; | 150 ResourceEntry entry; |
150 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 151 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
151 GetLocalResourceEntry(remote_dest_path, &entry)); | 152 GetLocalResourceEntry(remote_dest_path, &entry)); |
152 | 153 |
153 // Transfer the local file to Drive. | 154 // Transfer the local file to Drive. |
154 FileError error = FILE_ERROR_FAILED; | 155 FileError error = FILE_ERROR_FAILED; |
155 operation_->TransferFileFromLocalToRemote( | 156 operation_->TransferFileFromLocalToRemote( |
156 local_src_path, | 157 local_src_path, |
157 remote_dest_path, | 158 remote_dest_path, |
158 google_apis::test_util::CreateCopyResultCallback(&error)); | 159 google_apis::test_util::CreateCopyResultCallback(&error)); |
159 test_util::RunBlockingPoolTask(); | 160 content::RunAllBlockingPoolTasksUntilIdle(); |
160 EXPECT_EQ(FILE_ERROR_OK, error); | 161 EXPECT_EQ(FILE_ERROR_OK, error); |
161 | 162 |
162 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 163 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
163 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); | 164 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); |
164 EXPECT_TRUE(observer()->updated_local_ids().count(entry.local_id())); | 165 EXPECT_TRUE(observer()->updated_local_ids().count(entry.local_id())); |
165 | 166 |
166 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 167 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
167 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); | 168 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); |
168 // The original document got new parent. | 169 // The original document got new parent. |
169 EXPECT_EQ("document:orphan_doc_1", entry.resource_id()); | 170 EXPECT_EQ("document:orphan_doc_1", entry.resource_id()); |
170 } | 171 } |
171 | 172 |
172 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) { | 173 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) { |
173 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); | 174 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); |
174 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( | 175 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( |
175 "drive/root/Directory 1/moved.gdoc")); | 176 "drive/root/Directory 1/moved.gdoc")); |
176 | 177 |
177 // Create a hosted document on the server that is not synced to local yet. | 178 // Create a hosted document on the server that is not synced to local yet. |
178 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 179 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; |
179 scoped_ptr<google_apis::FileResource> new_gdoc_entry; | 180 scoped_ptr<google_apis::FileResource> new_gdoc_entry; |
180 fake_service()->AddNewFile( | 181 fake_service()->AddNewFile( |
181 "application/vnd.google-apps.document", "", "", "title", true, | 182 "application/vnd.google-apps.document", "", "", "title", true, |
182 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | 183 google_apis::test_util::CreateCopyResultCallback(&gdata_error, |
183 &new_gdoc_entry)); | 184 &new_gdoc_entry)); |
184 test_util::RunBlockingPoolTask(); | 185 content::RunAllBlockingPoolTasksUntilIdle(); |
185 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); | 186 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); |
186 | 187 |
187 // Prepare a local file, which is a json file of the added hosted document. | 188 // Prepare a local file, which is a json file of the added hosted document. |
188 ASSERT_TRUE(util::CreateGDocFile( | 189 ASSERT_TRUE(util::CreateGDocFile( |
189 local_src_path, | 190 local_src_path, |
190 GURL("https://3_document_self_link/" + new_gdoc_entry->file_id()), | 191 GURL("https://3_document_self_link/" + new_gdoc_entry->file_id()), |
191 new_gdoc_entry->file_id())); | 192 new_gdoc_entry->file_id())); |
192 | 193 |
193 ResourceEntry entry; | 194 ResourceEntry entry; |
194 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 195 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
195 GetLocalResourceEntry(remote_dest_path, &entry)); | 196 GetLocalResourceEntry(remote_dest_path, &entry)); |
196 | 197 |
197 // Transfer the local file to Drive. | 198 // Transfer the local file to Drive. |
198 FileError error = FILE_ERROR_FAILED; | 199 FileError error = FILE_ERROR_FAILED; |
199 operation_->TransferFileFromLocalToRemote( | 200 operation_->TransferFileFromLocalToRemote( |
200 local_src_path, | 201 local_src_path, |
201 remote_dest_path, | 202 remote_dest_path, |
202 google_apis::test_util::CreateCopyResultCallback(&error)); | 203 google_apis::test_util::CreateCopyResultCallback(&error)); |
203 test_util::RunBlockingPoolTask(); | 204 content::RunAllBlockingPoolTasksUntilIdle(); |
204 EXPECT_EQ(FILE_ERROR_OK, error); | 205 EXPECT_EQ(FILE_ERROR_OK, error); |
205 | 206 |
206 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 207 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
207 | 208 |
208 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 209 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
209 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); | 210 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); |
210 // The original document got new parent. | 211 // The original document got new parent. |
211 EXPECT_EQ(new_gdoc_entry->file_id(), entry.resource_id()); | 212 EXPECT_EQ(new_gdoc_entry->file_id(), entry.resource_id()); |
212 } | 213 } |
213 | 214 |
214 TEST_F(CopyOperationTest, CopyNotExistingFile) { | 215 TEST_F(CopyOperationTest, CopyNotExistingFile) { |
215 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 216 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
216 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 217 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
217 | 218 |
218 ResourceEntry entry; | 219 ResourceEntry entry; |
219 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); | 220 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
220 | 221 |
221 FileError error = FILE_ERROR_OK; | 222 FileError error = FILE_ERROR_OK; |
222 operation_->Copy(src_path, | 223 operation_->Copy(src_path, |
223 dest_path, | 224 dest_path, |
224 false, | 225 false, |
225 google_apis::test_util::CreateCopyResultCallback(&error)); | 226 google_apis::test_util::CreateCopyResultCallback(&error)); |
226 test_util::RunBlockingPoolTask(); | 227 content::RunAllBlockingPoolTasksUntilIdle(); |
227 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 228 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
228 | 229 |
229 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); | 230 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
230 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 231 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
231 EXPECT_TRUE(observer()->get_changed_files().empty()); | 232 EXPECT_TRUE(observer()->get_changed_files().empty()); |
232 } | 233 } |
233 | 234 |
234 TEST_F(CopyOperationTest, CopyFileToNonExistingDirectory) { | 235 TEST_F(CopyOperationTest, CopyFileToNonExistingDirectory) { |
235 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 236 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
236 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); | 237 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
237 | 238 |
238 ResourceEntry entry; | 239 ResourceEntry entry; |
239 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 240 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
240 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 241 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
241 GetLocalResourceEntry(dest_path.DirName(), &entry)); | 242 GetLocalResourceEntry(dest_path.DirName(), &entry)); |
242 | 243 |
243 FileError error = FILE_ERROR_OK; | 244 FileError error = FILE_ERROR_OK; |
244 operation_->Copy(src_path, | 245 operation_->Copy(src_path, |
245 dest_path, | 246 dest_path, |
246 false, | 247 false, |
247 google_apis::test_util::CreateCopyResultCallback(&error)); | 248 google_apis::test_util::CreateCopyResultCallback(&error)); |
248 test_util::RunBlockingPoolTask(); | 249 content::RunAllBlockingPoolTasksUntilIdle(); |
249 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 250 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
250 | 251 |
251 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 252 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
252 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 253 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
253 EXPECT_TRUE(observer()->get_changed_files().empty()); | 254 EXPECT_TRUE(observer()->get_changed_files().empty()); |
254 } | 255 } |
255 | 256 |
256 // Test the case where the parent of the destination path is an existing file, | 257 // Test the case where the parent of the destination path is an existing file, |
257 // not a directory. | 258 // not a directory. |
258 TEST_F(CopyOperationTest, CopyFileToInvalidPath) { | 259 TEST_F(CopyOperationTest, CopyFileToInvalidPath) { |
259 base::FilePath src_path(FILE_PATH_LITERAL( | 260 base::FilePath src_path(FILE_PATH_LITERAL( |
260 "drive/root/Document 1 excludeDir-test.gdoc")); | 261 "drive/root/Document 1 excludeDir-test.gdoc")); |
261 base::FilePath dest_path(FILE_PATH_LITERAL( | 262 base::FilePath dest_path(FILE_PATH_LITERAL( |
262 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc")); | 263 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc")); |
263 | 264 |
264 ResourceEntry entry; | 265 ResourceEntry entry; |
265 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 266 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
266 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry)); | 267 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry)); |
267 ASSERT_FALSE(entry.file_info().is_directory()); | 268 ASSERT_FALSE(entry.file_info().is_directory()); |
268 | 269 |
269 FileError error = FILE_ERROR_OK; | 270 FileError error = FILE_ERROR_OK; |
270 operation_->Copy(src_path, | 271 operation_->Copy(src_path, |
271 dest_path, | 272 dest_path, |
272 false, | 273 false, |
273 google_apis::test_util::CreateCopyResultCallback(&error)); | 274 google_apis::test_util::CreateCopyResultCallback(&error)); |
274 test_util::RunBlockingPoolTask(); | 275 content::RunAllBlockingPoolTasksUntilIdle(); |
275 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 276 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
276 | 277 |
277 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 278 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
278 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 279 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
279 EXPECT_TRUE(observer()->get_changed_files().empty()); | 280 EXPECT_TRUE(observer()->get_changed_files().empty()); |
280 } | 281 } |
281 | 282 |
282 TEST_F(CopyOperationTest, CopyDirtyFile) { | 283 TEST_F(CopyOperationTest, CopyDirtyFile) { |
283 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 284 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
284 base::FilePath dest_path(FILE_PATH_LITERAL( | 285 base::FilePath dest_path(FILE_PATH_LITERAL( |
(...skipping 11 matching lines...) Expand all Loading... |
296 base::PostTaskAndReplyWithResult( | 297 base::PostTaskAndReplyWithResult( |
297 blocking_task_runner(), | 298 blocking_task_runner(), |
298 FROM_HERE, | 299 FROM_HERE, |
299 base::Bind(&internal::FileCache::Store, | 300 base::Bind(&internal::FileCache::Store, |
300 base::Unretained(cache()), | 301 base::Unretained(cache()), |
301 src_entry.local_id(), | 302 src_entry.local_id(), |
302 std::string(), | 303 std::string(), |
303 temp_file, | 304 temp_file, |
304 internal::FileCache::FILE_OPERATION_MOVE), | 305 internal::FileCache::FILE_OPERATION_MOVE), |
305 google_apis::test_util::CreateCopyResultCallback(&error)); | 306 google_apis::test_util::CreateCopyResultCallback(&error)); |
306 test_util::RunBlockingPoolTask(); | 307 content::RunAllBlockingPoolTasksUntilIdle(); |
307 EXPECT_EQ(FILE_ERROR_OK, error); | 308 EXPECT_EQ(FILE_ERROR_OK, error); |
308 | 309 |
309 // Copy. | 310 // Copy. |
310 operation_->Copy(src_path, | 311 operation_->Copy(src_path, |
311 dest_path, | 312 dest_path, |
312 false, | 313 false, |
313 google_apis::test_util::CreateCopyResultCallback(&error)); | 314 google_apis::test_util::CreateCopyResultCallback(&error)); |
314 test_util::RunBlockingPoolTask(); | 315 content::RunAllBlockingPoolTasksUntilIdle(); |
315 EXPECT_EQ(FILE_ERROR_OK, error); | 316 EXPECT_EQ(FILE_ERROR_OK, error); |
316 | 317 |
317 ResourceEntry dest_entry; | 318 ResourceEntry dest_entry; |
318 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 319 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
319 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); | 320 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
320 | 321 |
321 EXPECT_EQ(1u, observer()->updated_local_ids().size()); | 322 EXPECT_EQ(1u, observer()->updated_local_ids().size()); |
322 EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); | 323 EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); |
323 EXPECT_EQ(1u, observer()->get_changed_files().size()); | 324 EXPECT_EQ(1u, observer()->get_changed_files().size()); |
324 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); | 325 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); |
325 | 326 |
326 // Copied cache file should be dirty. | 327 // Copied cache file should be dirty. |
327 EXPECT_TRUE(dest_entry.file_specific_info().cache_state().is_dirty()); | 328 EXPECT_TRUE(dest_entry.file_specific_info().cache_state().is_dirty()); |
328 | 329 |
329 // File contents should match. | 330 // File contents should match. |
330 base::FilePath cache_file_path; | 331 base::FilePath cache_file_path; |
331 base::PostTaskAndReplyWithResult( | 332 base::PostTaskAndReplyWithResult( |
332 blocking_task_runner(), | 333 blocking_task_runner(), |
333 FROM_HERE, | 334 FROM_HERE, |
334 base::Bind(&internal::FileCache::GetFile, | 335 base::Bind(&internal::FileCache::GetFile, |
335 base::Unretained(cache()), | 336 base::Unretained(cache()), |
336 dest_entry.local_id(), | 337 dest_entry.local_id(), |
337 &cache_file_path), | 338 &cache_file_path), |
338 google_apis::test_util::CreateCopyResultCallback(&error)); | 339 google_apis::test_util::CreateCopyResultCallback(&error)); |
339 test_util::RunBlockingPoolTask(); | 340 content::RunAllBlockingPoolTasksUntilIdle(); |
340 EXPECT_EQ(FILE_ERROR_OK, error); | 341 EXPECT_EQ(FILE_ERROR_OK, error); |
341 | 342 |
342 std::string copied_contents; | 343 std::string copied_contents; |
343 EXPECT_TRUE(base::ReadFileToString(cache_file_path, &copied_contents)); | 344 EXPECT_TRUE(base::ReadFileToString(cache_file_path, &copied_contents)); |
344 EXPECT_EQ(contents, copied_contents); | 345 EXPECT_EQ(contents, copied_contents); |
345 } | 346 } |
346 | 347 |
347 TEST_F(CopyOperationTest, CopyFileOverwriteFile) { | 348 TEST_F(CopyOperationTest, CopyFileOverwriteFile) { |
348 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 349 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
349 base::FilePath dest_path(FILE_PATH_LITERAL( | 350 base::FilePath dest_path(FILE_PATH_LITERAL( |
350 "drive/root/Directory 1/SubDirectory File 1.txt")); | 351 "drive/root/Directory 1/SubDirectory File 1.txt")); |
351 | 352 |
352 ResourceEntry old_dest_entry; | 353 ResourceEntry old_dest_entry; |
353 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &old_dest_entry)); | 354 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &old_dest_entry)); |
354 | 355 |
355 FileError error = FILE_ERROR_OK; | 356 FileError error = FILE_ERROR_OK; |
356 operation_->Copy(src_path, | 357 operation_->Copy(src_path, |
357 dest_path, | 358 dest_path, |
358 false, | 359 false, |
359 google_apis::test_util::CreateCopyResultCallback(&error)); | 360 google_apis::test_util::CreateCopyResultCallback(&error)); |
360 test_util::RunBlockingPoolTask(); | 361 content::RunAllBlockingPoolTasksUntilIdle(); |
361 EXPECT_EQ(FILE_ERROR_OK, error); | 362 EXPECT_EQ(FILE_ERROR_OK, error); |
362 | 363 |
363 ResourceEntry new_dest_entry; | 364 ResourceEntry new_dest_entry; |
364 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry)); | 365 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry)); |
365 | 366 |
366 EXPECT_EQ(1u, observer()->updated_local_ids().size()); | 367 EXPECT_EQ(1u, observer()->updated_local_ids().size()); |
367 EXPECT_TRUE(observer()->updated_local_ids().count(old_dest_entry.local_id())); | 368 EXPECT_TRUE(observer()->updated_local_ids().count(old_dest_entry.local_id())); |
368 EXPECT_EQ(1u, observer()->get_changed_files().size()); | 369 EXPECT_EQ(1u, observer()->get_changed_files().size()); |
369 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); | 370 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); |
370 } | 371 } |
371 | 372 |
372 TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) { | 373 TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) { |
373 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 374 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
374 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1")); | 375 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
375 | 376 |
376 FileError error = FILE_ERROR_OK; | 377 FileError error = FILE_ERROR_OK; |
377 operation_->Copy(src_path, | 378 operation_->Copy(src_path, |
378 dest_path, | 379 dest_path, |
379 false, | 380 false, |
380 google_apis::test_util::CreateCopyResultCallback(&error)); | 381 google_apis::test_util::CreateCopyResultCallback(&error)); |
381 test_util::RunBlockingPoolTask(); | 382 content::RunAllBlockingPoolTasksUntilIdle(); |
382 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); | 383 EXPECT_EQ(FILE_ERROR_INVALID_OPERATION, error); |
383 } | 384 } |
384 | 385 |
385 TEST_F(CopyOperationTest, CopyDirectory) { | 386 TEST_F(CopyOperationTest, CopyDirectory) { |
386 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Directory 1")); | 387 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Directory 1")); |
387 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/New Directory")); | 388 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/New Directory")); |
388 | 389 |
389 ResourceEntry entry; | 390 ResourceEntry entry; |
390 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 391 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
391 ASSERT_TRUE(entry.file_info().is_directory()); | 392 ASSERT_TRUE(entry.file_info().is_directory()); |
392 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry)); | 393 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry)); |
393 ASSERT_TRUE(entry.file_info().is_directory()); | 394 ASSERT_TRUE(entry.file_info().is_directory()); |
394 | 395 |
395 FileError error = FILE_ERROR_OK; | 396 FileError error = FILE_ERROR_OK; |
396 operation_->Copy(src_path, | 397 operation_->Copy(src_path, |
397 dest_path, | 398 dest_path, |
398 false, | 399 false, |
399 google_apis::test_util::CreateCopyResultCallback(&error)); | 400 google_apis::test_util::CreateCopyResultCallback(&error)); |
400 test_util::RunBlockingPoolTask(); | 401 content::RunAllBlockingPoolTasksUntilIdle(); |
401 EXPECT_EQ(FILE_ERROR_NOT_A_FILE, error); | 402 EXPECT_EQ(FILE_ERROR_NOT_A_FILE, error); |
402 } | 403 } |
403 | 404 |
404 TEST_F(CopyOperationTest, PreserveLastModified) { | 405 TEST_F(CopyOperationTest, PreserveLastModified) { |
405 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 406 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
406 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/File 2.txt")); | 407 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/File 2.txt")); |
407 | 408 |
408 ResourceEntry entry; | 409 ResourceEntry entry; |
409 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 410 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
410 ASSERT_EQ(FILE_ERROR_OK, | 411 ASSERT_EQ(FILE_ERROR_OK, |
411 GetLocalResourceEntry(dest_path.DirName(), &entry)); | 412 GetLocalResourceEntry(dest_path.DirName(), &entry)); |
412 | 413 |
413 FileError error = FILE_ERROR_OK; | 414 FileError error = FILE_ERROR_OK; |
414 operation_->Copy(src_path, | 415 operation_->Copy(src_path, |
415 dest_path, | 416 dest_path, |
416 true, // Preserve last modified. | 417 true, // Preserve last modified. |
417 google_apis::test_util::CreateCopyResultCallback(&error)); | 418 google_apis::test_util::CreateCopyResultCallback(&error)); |
418 test_util::RunBlockingPoolTask(); | 419 content::RunAllBlockingPoolTasksUntilIdle(); |
419 EXPECT_EQ(FILE_ERROR_OK, error); | 420 EXPECT_EQ(FILE_ERROR_OK, error); |
420 | 421 |
421 ResourceEntry entry2; | 422 ResourceEntry entry2; |
422 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 423 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
423 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2)); | 424 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2)); |
424 EXPECT_EQ(entry.file_info().last_modified(), | 425 EXPECT_EQ(entry.file_info().last_modified(), |
425 entry2.file_info().last_modified()); | 426 entry2.file_info().last_modified()); |
426 } | 427 } |
427 | 428 |
428 } // namespace file_system | 429 } // namespace file_system |
429 } // namespace drive | 430 } // namespace drive |
OLD | NEW |