| 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_system/operation_test_base.h" | 10 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 google_apis::test_util::CreateCopyResultCallback(&error)); | 55 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 56 test_util::RunBlockingPoolTask(); | 56 test_util::RunBlockingPoolTask(); |
| 57 EXPECT_EQ(FILE_ERROR_OK, error); | 57 EXPECT_EQ(FILE_ERROR_OK, error); |
| 58 | 58 |
| 59 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, | 59 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, |
| 60 // marks it dirty and requests the observer to upload the file. | 60 // marks it dirty and requests the observer to upload the file. |
| 61 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 61 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
| 62 EXPECT_EQ(1U, observer()->updated_local_ids().count( | 62 EXPECT_EQ(1U, observer()->updated_local_ids().count( |
| 63 GetLocalId(remote_dest_path))); | 63 GetLocalId(remote_dest_path))); |
| 64 FileCacheEntry cache_entry; | 64 FileCacheEntry cache_entry; |
| 65 bool found = false; | |
| 66 base::PostTaskAndReplyWithResult( | 65 base::PostTaskAndReplyWithResult( |
| 67 blocking_task_runner(), | 66 blocking_task_runner(), |
| 68 FROM_HERE, | 67 FROM_HERE, |
| 69 base::Bind(&internal::FileCache::GetCacheEntry, | 68 base::Bind(&internal::FileCache::GetCacheEntry, |
| 70 base::Unretained(cache()), | 69 base::Unretained(cache()), |
| 71 GetLocalId(remote_dest_path), | 70 GetLocalId(remote_dest_path), |
| 72 &cache_entry), | 71 &cache_entry), |
| 73 google_apis::test_util::CreateCopyResultCallback(&found)); | 72 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 74 test_util::RunBlockingPoolTask(); | 73 test_util::RunBlockingPoolTask(); |
| 75 EXPECT_TRUE(found); | 74 EXPECT_EQ(FILE_ERROR_OK, error); |
| 76 EXPECT_TRUE(cache_entry.is_present()); | 75 EXPECT_TRUE(cache_entry.is_present()); |
| 77 EXPECT_TRUE(cache_entry.is_dirty()); | 76 EXPECT_TRUE(cache_entry.is_dirty()); |
| 78 | 77 |
| 79 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 78 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 80 EXPECT_TRUE(observer()->get_changed_paths().count( | 79 EXPECT_TRUE(observer()->get_changed_paths().count( |
| 81 remote_dest_path.DirName())); | 80 remote_dest_path.DirName())); |
| 82 } | 81 } |
| 83 | 82 |
| 84 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) { | 83 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) { |
| 85 const base::FilePath local_src_path = temp_dir().AppendASCII("local.txt"); | 84 const base::FilePath local_src_path = temp_dir().AppendASCII("local.txt"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 remote_dest_path, | 99 remote_dest_path, |
| 101 google_apis::test_util::CreateCopyResultCallback(&error)); | 100 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 102 test_util::RunBlockingPoolTask(); | 101 test_util::RunBlockingPoolTask(); |
| 103 EXPECT_EQ(FILE_ERROR_OK, error); | 102 EXPECT_EQ(FILE_ERROR_OK, error); |
| 104 | 103 |
| 105 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, | 104 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, |
| 106 // marks it dirty and requests the observer to upload the file. | 105 // marks it dirty and requests the observer to upload the file. |
| 107 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 106 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
| 108 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); | 107 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); |
| 109 FileCacheEntry cache_entry; | 108 FileCacheEntry cache_entry; |
| 110 bool found = false; | |
| 111 base::PostTaskAndReplyWithResult( | 109 base::PostTaskAndReplyWithResult( |
| 112 blocking_task_runner(), | 110 blocking_task_runner(), |
| 113 FROM_HERE, | 111 FROM_HERE, |
| 114 base::Bind(&internal::FileCache::GetCacheEntry, | 112 base::Bind(&internal::FileCache::GetCacheEntry, |
| 115 base::Unretained(cache()), entry.local_id(), &cache_entry), | 113 base::Unretained(cache()), entry.local_id(), &cache_entry), |
| 116 google_apis::test_util::CreateCopyResultCallback(&found)); | 114 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 117 test_util::RunBlockingPoolTask(); | 115 test_util::RunBlockingPoolTask(); |
| 118 EXPECT_TRUE(found); | 116 EXPECT_EQ(FILE_ERROR_OK, error); |
| 119 EXPECT_TRUE(cache_entry.is_present()); | 117 EXPECT_TRUE(cache_entry.is_present()); |
| 120 EXPECT_TRUE(cache_entry.is_dirty()); | 118 EXPECT_TRUE(cache_entry.is_dirty()); |
| 121 | 119 |
| 122 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 120 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 123 EXPECT_TRUE(observer()->get_changed_paths().count( | 121 EXPECT_TRUE(observer()->get_changed_paths().count( |
| 124 remote_dest_path.DirName())); | 122 remote_dest_path.DirName())); |
| 125 } | 123 } |
| 126 | 124 |
| 127 TEST_F(CopyOperationTest, | 125 TEST_F(CopyOperationTest, |
| 128 TransferFileFromLocalToRemote_ExistingHostedDocument) { | 126 TransferFileFromLocalToRemote_ExistingHostedDocument) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 ResourceEntry dest_entry; | 342 ResourceEntry dest_entry; |
| 345 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 343 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 346 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); | 344 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 347 | 345 |
| 348 EXPECT_EQ(1u, observer()->updated_local_ids().size()); | 346 EXPECT_EQ(1u, observer()->updated_local_ids().size()); |
| 349 EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); | 347 EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); |
| 350 EXPECT_EQ(1u, observer()->get_changed_paths().size()); | 348 EXPECT_EQ(1u, observer()->get_changed_paths().size()); |
| 351 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); | 349 EXPECT_TRUE(observer()->get_changed_paths().count(dest_path.DirName())); |
| 352 | 350 |
| 353 // Copied cache file should be dirty. | 351 // Copied cache file should be dirty. |
| 354 bool success = false; | |
| 355 FileCacheEntry cache_entry; | 352 FileCacheEntry cache_entry; |
| 356 base::PostTaskAndReplyWithResult( | 353 base::PostTaskAndReplyWithResult( |
| 357 blocking_task_runner(), | 354 blocking_task_runner(), |
| 358 FROM_HERE, | 355 FROM_HERE, |
| 359 base::Bind(&internal::FileCache::GetCacheEntry, | 356 base::Bind(&internal::FileCache::GetCacheEntry, |
| 360 base::Unretained(cache()), | 357 base::Unretained(cache()), |
| 361 dest_entry.local_id(), | 358 dest_entry.local_id(), |
| 362 &cache_entry), | 359 &cache_entry), |
| 363 google_apis::test_util::CreateCopyResultCallback(&success)); | 360 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 364 test_util::RunBlockingPoolTask(); | 361 test_util::RunBlockingPoolTask(); |
| 365 EXPECT_TRUE(success); | 362 EXPECT_EQ(FILE_ERROR_OK, error); |
| 366 EXPECT_TRUE(cache_entry.is_dirty()); | 363 EXPECT_TRUE(cache_entry.is_dirty()); |
| 367 | 364 |
| 368 // File contents should match. | 365 // File contents should match. |
| 369 base::FilePath cache_file_path; | 366 base::FilePath cache_file_path; |
| 370 base::PostTaskAndReplyWithResult( | 367 base::PostTaskAndReplyWithResult( |
| 371 blocking_task_runner(), | 368 blocking_task_runner(), |
| 372 FROM_HERE, | 369 FROM_HERE, |
| 373 base::Bind(&internal::FileCache::GetFile, | 370 base::Bind(&internal::FileCache::GetFile, |
| 374 base::Unretained(cache()), | 371 base::Unretained(cache()), |
| 375 dest_entry.local_id(), | 372 dest_entry.local_id(), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 456 |
| 460 ResourceEntry entry2; | 457 ResourceEntry entry2; |
| 461 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 458 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 462 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2)); | 459 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry2)); |
| 463 EXPECT_EQ(entry.file_info().last_modified(), | 460 EXPECT_EQ(entry.file_info().last_modified(), |
| 464 entry2.file_info().last_modified()); | 461 entry2.file_info().last_modified()); |
| 465 } | 462 } |
| 466 | 463 |
| 467 } // namespace file_system | 464 } // namespace file_system |
| 468 } // namespace drive | 465 } // namespace drive |
| OLD | NEW |