| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/download_handler.h" | 5 #include "chrome/browser/chromeos/drive/download_handler.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "chrome/browser/chromeos/drive/dummy_file_system.h" | 8 #include "chrome/browser/chromeos/drive/dummy_file_system.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/chromeos/drive/test_util.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/test/mock_download_item.h" | 11 #include "content/public/test/mock_download_item.h" |
| 13 #include "content/public/test/mock_download_manager.h" | 12 #include "content/public/test/mock_download_manager.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "content/public/test/test_utils.h" |
| 15 #include "google_apis/drive/test_util.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace drive { | 18 namespace drive { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Test file system for verifying the behavior of DownloadHandler, by simulating | 22 // Test file system for verifying the behavior of DownloadHandler, by simulating |
| 22 // various responses from FileSystem. | 23 // various responses from FileSystem. |
| 23 class DownloadHandlerTestFileSystem : public DummyFileSystem { | 24 class DownloadHandlerTestFileSystem : public DummyFileSystem { |
| 24 public: | 25 public: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { | 78 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { |
| 78 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); | 79 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); |
| 79 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); | 80 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); |
| 80 | 81 |
| 81 // Call SubstituteDriveDownloadPath() | 82 // Call SubstituteDriveDownloadPath() |
| 82 base::FilePath substituted_path; | 83 base::FilePath substituted_path; |
| 83 download_handler_->SubstituteDriveDownloadPath( | 84 download_handler_->SubstituteDriveDownloadPath( |
| 84 non_drive_path, | 85 non_drive_path, |
| 85 &download_item_, | 86 &download_item_, |
| 86 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); | 87 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 87 test_util::RunBlockingPoolTask(); | 88 content::RunAllBlockingPoolTasksUntilIdle(); |
| 88 | 89 |
| 89 // Check the result. | 90 // Check the result. |
| 90 EXPECT_EQ(non_drive_path, substituted_path); | 91 EXPECT_EQ(non_drive_path, substituted_path); |
| 91 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); | 92 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); |
| 92 } | 93 } |
| 93 | 94 |
| 94 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPath) { | 95 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPath) { |
| 95 const base::FilePath drive_path = | 96 const base::FilePath drive_path = |
| 96 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); | 97 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); |
| 97 | 98 |
| 98 // Test the case that the download target directory already exists. | 99 // Test the case that the download target directory already exists. |
| 99 test_file_system_.set_error(FILE_ERROR_OK); | 100 test_file_system_.set_error(FILE_ERROR_OK); |
| 100 | 101 |
| 101 // Call SubstituteDriveDownloadPath() | 102 // Call SubstituteDriveDownloadPath() |
| 102 base::FilePath substituted_path; | 103 base::FilePath substituted_path; |
| 103 download_handler_->SubstituteDriveDownloadPath( | 104 download_handler_->SubstituteDriveDownloadPath( |
| 104 drive_path, | 105 drive_path, |
| 105 &download_item_, | 106 &download_item_, |
| 106 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); | 107 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 107 test_util::RunBlockingPoolTask(); | 108 content::RunAllBlockingPoolTasksUntilIdle(); |
| 108 | 109 |
| 109 // Check the result. | 110 // Check the result. |
| 110 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); | 111 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); |
| 111 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); | 112 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); |
| 112 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 113 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 113 } | 114 } |
| 114 | 115 |
| 115 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathGetEntryFailure) { | 116 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathGetEntryFailure) { |
| 116 const base::FilePath drive_path = | 117 const base::FilePath drive_path = |
| 117 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); | 118 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); |
| 118 | 119 |
| 119 // Test the case that access to the download target directory failed for some | 120 // Test the case that access to the download target directory failed for some |
| 120 // reason. | 121 // reason. |
| 121 test_file_system_.set_error(FILE_ERROR_FAILED); | 122 test_file_system_.set_error(FILE_ERROR_FAILED); |
| 122 | 123 |
| 123 // Call SubstituteDriveDownloadPath() | 124 // Call SubstituteDriveDownloadPath() |
| 124 base::FilePath substituted_path; | 125 base::FilePath substituted_path; |
| 125 download_handler_->SubstituteDriveDownloadPath( | 126 download_handler_->SubstituteDriveDownloadPath( |
| 126 drive_path, | 127 drive_path, |
| 127 &download_item_, | 128 &download_item_, |
| 128 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); | 129 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 129 test_util::RunBlockingPoolTask(); | 130 content::RunAllBlockingPoolTasksUntilIdle(); |
| 130 | 131 |
| 131 // Check the result. | 132 // Check the result. |
| 132 EXPECT_TRUE(substituted_path.empty()); | 133 EXPECT_TRUE(substituted_path.empty()); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // content::SavePackage calls SubstituteDriveDownloadPath before creating | 136 // content::SavePackage calls SubstituteDriveDownloadPath before creating |
| 136 // DownloadItem. | 137 // DownloadItem. |
| 137 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathForSavePackage) { | 138 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathForSavePackage) { |
| 138 const base::FilePath drive_path = | 139 const base::FilePath drive_path = |
| 139 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); | 140 util::GetDriveMountPointPath(&profile_).AppendASCII("test.dat"); |
| 140 test_file_system_.set_error(FILE_ERROR_OK); | 141 test_file_system_.set_error(FILE_ERROR_OK); |
| 141 | 142 |
| 142 // Call SubstituteDriveDownloadPath() | 143 // Call SubstituteDriveDownloadPath() |
| 143 base::FilePath substituted_path; | 144 base::FilePath substituted_path; |
| 144 download_handler_->SubstituteDriveDownloadPath( | 145 download_handler_->SubstituteDriveDownloadPath( |
| 145 drive_path, | 146 drive_path, |
| 146 NULL, // DownloadItem is not available at this moment. | 147 NULL, // DownloadItem is not available at this moment. |
| 147 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); | 148 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 148 test_util::RunBlockingPoolTask(); | 149 content::RunAllBlockingPoolTasksUntilIdle(); |
| 149 | 150 |
| 150 // Check the result of SubstituteDriveDownloadPath(). | 151 // Check the result of SubstituteDriveDownloadPath(). |
| 151 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); | 152 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); |
| 152 | 153 |
| 153 // |download_item_| is not a drive download yet. | 154 // |download_item_| is not a drive download yet. |
| 154 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); | 155 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); |
| 155 | 156 |
| 156 // Call SetDownloadParams(). | 157 // Call SetDownloadParams(). |
| 157 download_handler_->SetDownloadParams(drive_path, &download_item_); | 158 download_handler_->SetDownloadParams(drive_path, &download_item_); |
| 158 | 159 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 171 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 172 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 172 | 173 |
| 173 // Test for the case when the path exists. | 174 // Test for the case when the path exists. |
| 174 test_file_system_.set_error(FILE_ERROR_OK); | 175 test_file_system_.set_error(FILE_ERROR_OK); |
| 175 | 176 |
| 176 // Call CheckForFileExistence. | 177 // Call CheckForFileExistence. |
| 177 bool file_exists = false; | 178 bool file_exists = false; |
| 178 download_handler_->CheckForFileExistence( | 179 download_handler_->CheckForFileExistence( |
| 179 &download_item_, | 180 &download_item_, |
| 180 google_apis::test_util::CreateCopyResultCallback(&file_exists)); | 181 google_apis::test_util::CreateCopyResultCallback(&file_exists)); |
| 181 test_util::RunBlockingPoolTask(); | 182 content::RunAllBlockingPoolTasksUntilIdle(); |
| 182 | 183 |
| 183 // Check the result. | 184 // Check the result. |
| 184 EXPECT_TRUE(file_exists); | 185 EXPECT_TRUE(file_exists); |
| 185 | 186 |
| 186 // Test for the case when the path does not exist. | 187 // Test for the case when the path does not exist. |
| 187 test_file_system_.set_error(FILE_ERROR_NOT_FOUND); | 188 test_file_system_.set_error(FILE_ERROR_NOT_FOUND); |
| 188 | 189 |
| 189 // Call CheckForFileExistence again. | 190 // Call CheckForFileExistence again. |
| 190 download_handler_->CheckForFileExistence( | 191 download_handler_->CheckForFileExistence( |
| 191 &download_item_, | 192 &download_item_, |
| 192 google_apis::test_util::CreateCopyResultCallback(&file_exists)); | 193 google_apis::test_util::CreateCopyResultCallback(&file_exists)); |
| 193 test_util::RunBlockingPoolTask(); | 194 content::RunAllBlockingPoolTasksUntilIdle(); |
| 194 | 195 |
| 195 // Check the result. | 196 // Check the result. |
| 196 EXPECT_FALSE(file_exists); | 197 EXPECT_FALSE(file_exists); |
| 197 } | 198 } |
| 198 | 199 |
| 199 } // namespace drive | 200 } // namespace drive |
| OLD | NEW |