| 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 "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/drive/fake_drive_service.h" | 10 #include "chrome/browser/drive/fake_drive_service.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); | 137 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); |
| 138 | 138 |
| 139 // We added a file to the Drive root and then moved to "Directory 1". | 139 // We added a file to the Drive root and then moved to "Directory 1". |
| 140 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | 140 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
| 141 EXPECT_TRUE(observer()->get_changed_paths().count( | 141 EXPECT_TRUE(observer()->get_changed_paths().count( |
| 142 base::FilePath(FILE_PATH_LITERAL("drive/root")))); | 142 base::FilePath(FILE_PATH_LITERAL("drive/root")))); |
| 143 EXPECT_TRUE(observer()->get_changed_paths().count( | 143 EXPECT_TRUE(observer()->get_changed_paths().count( |
| 144 remote_dest_path.DirName())); | 144 remote_dest_path.DirName())); |
| 145 } | 145 } |
| 146 | 146 |
| 147 TEST_F(CopyOperationTest, TransferFileFromRemoteToLocal_RegularFile) { | |
| 148 base::FilePath remote_src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 149 base::FilePath local_dest_path = temp_dir().AppendASCII("local_copy.txt"); | |
| 150 | |
| 151 ResourceEntry entry; | |
| 152 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_src_path, &entry)); | |
| 153 | |
| 154 FileError error = FILE_ERROR_FAILED; | |
| 155 operation_->TransferFileFromRemoteToLocal( | |
| 156 remote_src_path, | |
| 157 local_dest_path, | |
| 158 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 159 test_util::RunBlockingPoolTask(); | |
| 160 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 161 | |
| 162 // The content is "x"s of the file size. | |
| 163 base::FilePath cache_path; | |
| 164 cache()->GetFileOnUIThread(entry.resource_id(), | |
| 165 google_apis::test_util::CreateCopyResultCallback( | |
| 166 &error, &cache_path)); | |
| 167 test_util::RunBlockingPoolTask(); | |
| 168 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 169 | |
| 170 const std::string kExpectedContent = "This is some test content."; | |
| 171 std::string cache_file_data; | |
| 172 EXPECT_TRUE(file_util::ReadFileToString(cache_path, &cache_file_data)); | |
| 173 EXPECT_EQ(kExpectedContent, cache_file_data); | |
| 174 | |
| 175 std::string local_dest_file_data; | |
| 176 EXPECT_TRUE(file_util::ReadFileToString(local_dest_path, | |
| 177 &local_dest_file_data)); | |
| 178 EXPECT_EQ(kExpectedContent, local_dest_file_data); | |
| 179 | |
| 180 // The transfered file is cached and the change of "offline available" | |
| 181 // attribute is notified. | |
| 182 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | |
| 183 EXPECT_TRUE(observer()->get_changed_paths().count(remote_src_path.DirName())); | |
| 184 } | |
| 185 | |
| 186 TEST_F(CopyOperationTest, TransferFileFromRemoteToLocal_HostedDocument) { | |
| 187 base::FilePath local_dest_path = temp_dir().AppendASCII("local_copy.txt"); | |
| 188 base::FilePath remote_src_path( | |
| 189 FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc")); | |
| 190 | |
| 191 FileError error = FILE_ERROR_FAILED; | |
| 192 operation_->TransferFileFromRemoteToLocal( | |
| 193 remote_src_path, | |
| 194 local_dest_path, | |
| 195 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 196 test_util::RunBlockingPoolTask(); | |
| 197 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 198 | |
| 199 ResourceEntry entry; | |
| 200 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_src_path, &entry)); | |
| 201 EXPECT_EQ(GURL(entry.file_specific_info().alternate_url()), | |
| 202 util::ReadUrlFromGDocFile(local_dest_path)); | |
| 203 EXPECT_EQ(entry.resource_id(), | |
| 204 util::ReadResourceIdFromGDocFile(local_dest_path)); | |
| 205 EXPECT_TRUE(observer()->get_changed_paths().empty()); | |
| 206 } | |
| 207 | 147 |
| 208 TEST_F(CopyOperationTest, CopyNotExistingFile) { | 148 TEST_F(CopyOperationTest, CopyNotExistingFile) { |
| 209 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 149 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
| 210 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 150 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 211 | 151 |
| 212 ResourceEntry entry; | 152 ResourceEntry entry; |
| 213 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); | 153 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); |
| 214 | 154 |
| 215 FileError error = FILE_ERROR_OK; | 155 FileError error = FILE_ERROR_OK; |
| 216 operation_->Copy(src_path, | 156 operation_->Copy(src_path, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 test_util::RunBlockingPoolTask(); | 205 test_util::RunBlockingPoolTask(); |
| 266 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 206 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 267 | 207 |
| 268 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); | 208 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); |
| 269 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); | 209 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); |
| 270 EXPECT_TRUE(observer()->get_changed_paths().empty()); | 210 EXPECT_TRUE(observer()->get_changed_paths().empty()); |
| 271 } | 211 } |
| 272 | 212 |
| 273 } // namespace file_system | 213 } // namespace file_system |
| 274 } // namespace drive | 214 } // namespace drive |
| OLD | NEW |