| 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/move_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/file_change.h" | 7 #include "chrome/browser/chromeos/drive/file_change.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 "content/public/test/test_utils.h" |
| 9 #include "google_apis/drive/test_util.h" | 10 #include "google_apis/drive/test_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace drive { | 13 namespace drive { |
| 13 namespace file_system { | 14 namespace file_system { |
| 14 | 15 |
| 15 class MoveOperationTest : public OperationTestBase { | 16 class MoveOperationTest : public OperationTestBase { |
| 16 protected: | 17 protected: |
| 17 virtual void SetUp() OVERRIDE { | 18 virtual void SetUp() OVERRIDE { |
| 18 OperationTestBase::SetUp(); | 19 OperationTestBase::SetUp(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 | 33 |
| 33 ResourceEntry src_entry, dest_entry; | 34 ResourceEntry src_entry, dest_entry; |
| 34 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | 35 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 35 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 36 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 36 GetLocalResourceEntry(dest_path, &dest_entry)); | 37 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 37 | 38 |
| 38 FileError error = FILE_ERROR_FAILED; | 39 FileError error = FILE_ERROR_FAILED; |
| 39 operation_->Move(src_path, | 40 operation_->Move(src_path, |
| 40 dest_path, | 41 dest_path, |
| 41 google_apis::test_util::CreateCopyResultCallback(&error)); | 42 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 42 test_util::RunBlockingPoolTask(); | 43 content::RunAllBlockingPoolTasksUntilIdle(); |
| 43 EXPECT_EQ(FILE_ERROR_OK, error); | 44 EXPECT_EQ(FILE_ERROR_OK, error); |
| 44 | 45 |
| 45 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 46 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 46 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | 47 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); |
| 47 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); | 48 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 48 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | 49 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 49 | 50 |
| 50 EXPECT_EQ(2U, observer()->get_changed_files().size()); | 51 EXPECT_EQ(2U, observer()->get_changed_files().size()); |
| 51 EXPECT_TRUE(observer()->get_changed_files().count(src_path)); | 52 EXPECT_TRUE(observer()->get_changed_files().count(src_path)); |
| 52 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); | 53 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); |
| 53 | 54 |
| 54 EXPECT_EQ(1U, observer()->updated_local_ids().size()); | 55 EXPECT_EQ(1U, observer()->updated_local_ids().size()); |
| 55 EXPECT_TRUE(observer()->updated_local_ids().count(src_entry.local_id())); | 56 EXPECT_TRUE(observer()->updated_local_ids().count(src_entry.local_id())); |
| 56 } | 57 } |
| 57 | 58 |
| 58 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { | 59 TEST_F(MoveOperationTest, MoveFileFromRootToSubDirectory) { |
| 59 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 60 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 60 base::FilePath dest_path( | 61 base::FilePath dest_path( |
| 61 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); | 62 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log")); |
| 62 | 63 |
| 63 ResourceEntry src_entry, dest_entry; | 64 ResourceEntry src_entry, dest_entry; |
| 64 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); | 65 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); |
| 65 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 66 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
| 66 GetLocalResourceEntry(dest_path, &dest_entry)); | 67 GetLocalResourceEntry(dest_path, &dest_entry)); |
| 67 | 68 |
| 68 FileError error = FILE_ERROR_FAILED; | 69 FileError error = FILE_ERROR_FAILED; |
| 69 operation_->Move(src_path, | 70 operation_->Move(src_path, |
| 70 dest_path, | 71 dest_path, |
| 71 google_apis::test_util::CreateCopyResultCallback(&error)); | 72 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 72 test_util::RunBlockingPoolTask(); | 73 content::RunAllBlockingPoolTasksUntilIdle(); |
| 73 EXPECT_EQ(FILE_ERROR_OK, error); | 74 EXPECT_EQ(FILE_ERROR_OK, error); |
| 74 | 75 |
| 75 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); | 76 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); |
| 76 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); | 77 EXPECT_EQ(src_entry.local_id(), dest_entry.local_id()); |
| 77 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); | 78 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); |
| 78 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); | 79 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &src_entry)); |
| 79 | 80 |
| 80 EXPECT_EQ(2U, observer()->get_changed_files().size()); | 81 EXPECT_EQ(2U, observer()->get_changed_files().size()); |
| 81 EXPECT_TRUE(observer()->get_changed_files().count(src_path)); | 82 EXPECT_TRUE(observer()->get_changed_files().count(src_path)); |
| 82 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); | 83 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); |
| 83 | 84 |
| 84 EXPECT_EQ(1U, observer()->updated_local_ids().size()); | 85 EXPECT_EQ(1U, observer()->updated_local_ids().size()); |
| 85 EXPECT_TRUE(observer()->updated_local_ids().count(src_entry.local_id())); | 86 EXPECT_TRUE(observer()->updated_local_ids().count(src_entry.local_id())); |
| 86 } | 87 } |
| 87 | 88 |
| 88 TEST_F(MoveOperationTest, MoveNotExistingFile) { | 89 TEST_F(MoveOperationTest, MoveNotExistingFile) { |
| 89 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 90 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 90 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 91 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 91 | 92 |
| 92 FileError error = FILE_ERROR_OK; | 93 FileError error = FILE_ERROR_OK; |
| 93 operation_->Move(src_path, | 94 operation_->Move(src_path, |
| 94 dest_path, | 95 dest_path, |
| 95 google_apis::test_util::CreateCopyResultCallback(&error)); | 96 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 96 test_util::RunBlockingPoolTask(); | 97 content::RunAllBlockingPoolTasksUntilIdle(); |
| 97 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 98 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 98 | 99 |
| 99 ResourceEntry entry; | 100 ResourceEntry entry; |
| 100 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); | 101 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
| 101 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 102 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 TEST_F(MoveOperationTest, MoveFileToNonExistingDirectory) { | 105 TEST_F(MoveOperationTest, MoveFileToNonExistingDirectory) { |
| 105 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 106 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 106 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); | 107 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); |
| 107 | 108 |
| 108 FileError error = FILE_ERROR_OK; | 109 FileError error = FILE_ERROR_OK; |
| 109 operation_->Move(src_path, | 110 operation_->Move(src_path, |
| 110 dest_path, | 111 dest_path, |
| 111 google_apis::test_util::CreateCopyResultCallback(&error)); | 112 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 112 test_util::RunBlockingPoolTask(); | 113 content::RunAllBlockingPoolTasksUntilIdle(); |
| 113 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 114 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
| 114 | 115 |
| 115 ResourceEntry entry; | 116 ResourceEntry entry; |
| 116 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 117 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 117 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 118 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 118 } | 119 } |
| 119 | 120 |
| 120 // Test the case where the parent of |dest_file_path| is a existing file, | 121 // Test the case where the parent of |dest_file_path| is a existing file, |
| 121 // not a directory. | 122 // not a directory. |
| 122 TEST_F(MoveOperationTest, MoveFileToInvalidPath) { | 123 TEST_F(MoveOperationTest, MoveFileToInvalidPath) { |
| 123 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 124 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 124 base::FilePath dest_path( | 125 base::FilePath dest_path( |
| 125 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log")); | 126 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log")); |
| 126 | 127 |
| 127 FileError error = FILE_ERROR_OK; | 128 FileError error = FILE_ERROR_OK; |
| 128 operation_->Move(src_path, | 129 operation_->Move(src_path, |
| 129 dest_path, | 130 dest_path, |
| 130 google_apis::test_util::CreateCopyResultCallback(&error)); | 131 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 131 test_util::RunBlockingPoolTask(); | 132 content::RunAllBlockingPoolTasksUntilIdle(); |
| 132 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 133 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 133 | 134 |
| 134 ResourceEntry entry; | 135 ResourceEntry entry; |
| 135 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 136 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 136 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 137 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace file_system | 140 } // namespace file_system |
| 140 } // namespace drive | 141 } // namespace drive |
| OLD | NEW |