| 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/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_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/fake_free_disk_space_getter.h" | 9 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
| 10 #include "chrome/browser/chromeos/drive/file_cache.h" | 10 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 11 #include "chrome/browser/chromeos/drive/file_change.h" | 11 #include "chrome/browser/chromeos/drive/file_change.h" |
| 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 12 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 15 #include "chrome/browser/drive/fake_drive_service.h" | 15 #include "chrome/browser/drive/fake_drive_service.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 #include "google_apis/drive/test_util.h" | 17 #include "google_apis/drive/test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/cros_system_api/constants/cryptohome.h" | 19 #include "third_party/cros_system_api/constants/cryptohome.h" |
| 20 | 20 |
| 21 namespace drive { | 21 namespace drive { |
| 22 namespace file_system { | 22 namespace file_system { |
| 23 | 23 |
| 24 class DownloadOperationTest : public OperationTestBase { | 24 class DownloadOperationTest : public OperationTestBase { |
| 25 protected: | 25 protected: |
| 26 virtual void SetUp() OVERRIDE { | 26 virtual void SetUp() OVERRIDE { |
| 27 OperationTestBase::SetUp(); | 27 OperationTestBase::SetUp(); |
| 28 | 28 |
| 29 operation_.reset(new DownloadOperation( | 29 operation_.reset(new DownloadOperation( |
| 30 blocking_task_runner(), observer(), scheduler(), metadata(), cache(), | 30 blocking_task_runner(), delegate(), scheduler(), metadata(), cache(), |
| 31 temp_dir())); | 31 temp_dir())); |
| 32 } | 32 } |
| 33 | 33 |
| 34 scoped_ptr<DownloadOperation> operation_; | 34 scoped_ptr<DownloadOperation> operation_; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 TEST_F(DownloadOperationTest, | 37 TEST_F(DownloadOperationTest, |
| 38 EnsureFileDownloadedByPath_FromServer_EnoughSpace) { | 38 EnsureFileDownloadedByPath_FromServer_EnoughSpace) { |
| 39 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 39 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 40 ResourceEntry src_entry; | 40 ResourceEntry src_entry; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 google_apis::test_util::CreateCopyResultCallback( | 56 google_apis::test_util::CreateCopyResultCallback( |
| 57 &error, &file_path, &entry)); | 57 &error, &file_path, &entry)); |
| 58 content::RunAllBlockingPoolTasksUntilIdle(); | 58 content::RunAllBlockingPoolTasksUntilIdle(); |
| 59 | 59 |
| 60 EXPECT_EQ(FILE_ERROR_OK, error); | 60 EXPECT_EQ(FILE_ERROR_OK, error); |
| 61 ASSERT_TRUE(entry); | 61 ASSERT_TRUE(entry); |
| 62 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 62 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 63 | 63 |
| 64 // The transfered file is cached and the change of "offline available" | 64 // The transfered file is cached and the change of "offline available" |
| 65 // attribute is notified. | 65 // attribute is notified. |
| 66 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 66 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
| 67 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); | 67 EXPECT_EQ(1U, delegate()->get_changed_files().count(file_in_root)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(DownloadOperationTest, | 70 TEST_F(DownloadOperationTest, |
| 71 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { | 71 EnsureFileDownloadedByPath_FromServer_NoSpaceAtAll) { |
| 72 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 72 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 73 | 73 |
| 74 // Pretend we have no space at all. | 74 // Pretend we have no space at all. |
| 75 fake_free_disk_space_getter()->set_default_value(0); | 75 fake_free_disk_space_getter()->set_default_value(0); |
| 76 | 76 |
| 77 FileError error = FILE_ERROR_OK; | 77 FileError error = FILE_ERROR_OK; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 google_apis::test_util::CreateCopyResultCallback( | 130 google_apis::test_util::CreateCopyResultCallback( |
| 131 &error, &file_path, &entry)); | 131 &error, &file_path, &entry)); |
| 132 content::RunAllBlockingPoolTasksUntilIdle(); | 132 content::RunAllBlockingPoolTasksUntilIdle(); |
| 133 | 133 |
| 134 EXPECT_EQ(FILE_ERROR_OK, error); | 134 EXPECT_EQ(FILE_ERROR_OK, error); |
| 135 ASSERT_TRUE(entry); | 135 ASSERT_TRUE(entry); |
| 136 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 136 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 137 | 137 |
| 138 // The transfered file is cached and the change of "offline available" | 138 // The transfered file is cached and the change of "offline available" |
| 139 // attribute is notified. | 139 // attribute is notified. |
| 140 EXPECT_EQ(2U, observer()->get_changed_files().size()); | 140 EXPECT_EQ(2U, delegate()->get_changed_files().size()); |
| 141 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); | 141 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); |
| 142 EXPECT_TRUE(observer()->get_changed_files().count(cached_file)); | 142 EXPECT_TRUE(delegate()->get_changed_files().count(cached_file)); |
| 143 | 143 |
| 144 // The cache for the other file should be removed in order to free up space. | 144 // The cache for the other file should be removed in order to free up space. |
| 145 ResourceEntry cached_file_entry; | 145 ResourceEntry cached_file_entry; |
| 146 EXPECT_EQ(FILE_ERROR_OK, | 146 EXPECT_EQ(FILE_ERROR_OK, |
| 147 GetLocalResourceEntry(cached_file, &cached_file_entry)); | 147 GetLocalResourceEntry(cached_file, &cached_file_entry)); |
| 148 EXPECT_FALSE( | 148 EXPECT_FALSE( |
| 149 cached_file_entry.file_specific_info().cache_state().is_present()); | 149 cached_file_entry.file_specific_info().cache_state().is_present()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(DownloadOperationTest, | 152 TEST_F(DownloadOperationTest, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 google_apis::test_util::CreateCopyResultCallback( | 262 google_apis::test_util::CreateCopyResultCallback( |
| 263 &error, &file_path, &entry)); | 263 &error, &file_path, &entry)); |
| 264 content::RunAllBlockingPoolTasksUntilIdle(); | 264 content::RunAllBlockingPoolTasksUntilIdle(); |
| 265 | 265 |
| 266 EXPECT_EQ(FILE_ERROR_OK, error); | 266 EXPECT_EQ(FILE_ERROR_OK, error); |
| 267 ASSERT_TRUE(entry); | 267 ASSERT_TRUE(entry); |
| 268 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | 268 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); |
| 269 | 269 |
| 270 // The transfered file is cached and the change of "offline available" | 270 // The transfered file is cached and the change of "offline available" |
| 271 // attribute is notified. | 271 // attribute is notified. |
| 272 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 272 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
| 273 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); | 273 EXPECT_EQ(1U, delegate()->get_changed_files().count(file_in_root)); |
| 274 } | 274 } |
| 275 | 275 |
| 276 TEST_F(DownloadOperationTest, | 276 TEST_F(DownloadOperationTest, |
| 277 EnsureFileDownloadedByPath_WithGetContentCallback) { | 277 EnsureFileDownloadedByPath_WithGetContentCallback) { |
| 278 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 278 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 279 | 279 |
| 280 { | 280 { |
| 281 FileError initialized_error = FILE_ERROR_FAILED; | 281 FileError initialized_error = FILE_ERROR_FAILED; |
| 282 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 282 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
| 283 base::FilePath local_path, local_path_dontcare; | 283 base::FilePath local_path, local_path_dontcare; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 299 ASSERT_TRUE(entry); | 299 ASSERT_TRUE(entry); |
| 300 ASSERT_TRUE(local_path.empty()); | 300 ASSERT_TRUE(local_path.empty()); |
| 301 EXPECT_FALSE(cancel_download.is_null()); | 301 EXPECT_FALSE(cancel_download.is_null()); |
| 302 // Content is available through the second callback argument. | 302 // Content is available through the second callback argument. |
| 303 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), | 303 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), |
| 304 get_content_callback.GetConcatenatedData().size()); | 304 get_content_callback.GetConcatenatedData().size()); |
| 305 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 305 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
| 306 | 306 |
| 307 // The transfered file is cached and the change of "offline available" | 307 // The transfered file is cached and the change of "offline available" |
| 308 // attribute is notified. | 308 // attribute is notified. |
| 309 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 309 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
| 310 EXPECT_EQ(1U, observer()->get_changed_files().count(file_in_root)); | 310 EXPECT_EQ(1U, delegate()->get_changed_files().count(file_in_root)); |
| 311 } | 311 } |
| 312 | 312 |
| 313 { | 313 { |
| 314 FileError initialized_error = FILE_ERROR_FAILED; | 314 FileError initialized_error = FILE_ERROR_FAILED; |
| 315 scoped_ptr<ResourceEntry> entry, entry_dontcare; | 315 scoped_ptr<ResourceEntry> entry, entry_dontcare; |
| 316 base::FilePath local_path, local_path_dontcare; | 316 base::FilePath local_path, local_path_dontcare; |
| 317 google_apis::test_util::TestGetContentCallback get_content_callback; | 317 google_apis::test_util::TestGetContentCallback get_content_callback; |
| 318 FileError completion_error = FILE_ERROR_FAILED; | 318 FileError completion_error = FILE_ERROR_FAILED; |
| 319 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( | 319 base::Closure cancel_download = operation_->EnsureFileDownloadedByPath( |
| 320 file_in_root, | 320 file_in_root, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 // Cancel immediately. | 496 // Cancel immediately. |
| 497 ASSERT_FALSE(cancel_closure.is_null()); | 497 ASSERT_FALSE(cancel_closure.is_null()); |
| 498 cancel_closure.Run(); | 498 cancel_closure.Run(); |
| 499 content::RunAllBlockingPoolTasksUntilIdle(); | 499 content::RunAllBlockingPoolTasksUntilIdle(); |
| 500 | 500 |
| 501 EXPECT_EQ(FILE_ERROR_ABORT, error); | 501 EXPECT_EQ(FILE_ERROR_ABORT, error); |
| 502 } | 502 } |
| 503 | 503 |
| 504 } // namespace file_system | 504 } // namespace file_system |
| 505 } // namespace drive | 505 } // namespace drive |
| OLD | NEW |