Chromium Code Reviews| 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 "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/chromeos/drive/dummy_file_system.h" | |
| 9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 10 #include "chrome/browser/chromeos/drive/file_write_helper.h" | 11 #include "chrome/browser/chromeos/drive/file_write_helper.h" |
| 11 #include "chrome/browser/chromeos/drive/mock_file_system.h" | |
| 12 #include "chrome/browser/google_apis/test_util.h" | 12 #include "chrome/browser/google_apis/test_util.h" |
| 13 #include "content/public/test/mock_download_item.h" | 13 #include "content/public/test/mock_download_item.h" |
| 14 #include "content/public/test/mock_download_manager.h" | 14 #include "content/public/test/mock_download_manager.h" |
| 15 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using ::testing::Return; | |
| 20 using ::testing::SaveArg; | |
| 21 using ::testing::_; | |
| 22 | |
| 23 namespace drive { | 19 namespace drive { |
| 24 | 20 |
| 25 namespace { | 21 namespace { |
| 26 | 22 |
| 27 // Copies |file_path| to |out_file_path|, is used as a | 23 // Flags to control the state of the test file system. |
| 28 // SubstituteDriveDownloadPathCallback. | 24 enum DownloadPathState { |
| 29 void CopySubstituteDriveDownloadPathResult(base::FilePath* out_file_path, | 25 // Simulates the state that requested path just simply exists. |
| 30 const base::FilePath& file_path) { | 26 PATH_EXISTS, |
| 31 *out_file_path = file_path; | 27 // Simulates the state that requested path fails to be accessed. |
| 32 } | 28 PATH_INVALID, |
| 29 // Simulates the state that the requested path does not exist. | |
| 30 PATH_NOT_EXIST, | |
| 31 // Simulates the state that the path does not exist nor be able to be created. | |
| 32 PATH_NOT_EXIST_AND_CREATE_FAIL, | |
| 33 }; | |
| 33 | 34 |
| 34 // Copies |value| to |out|, is used as a content::CheckForFileExistenceCallback. | 35 // Test file system to |
|
hashimoto
2013/06/04 00:53:09
nit: "Test file system to DownloadHandlerTest"?
kinaba
2013/06/04 03:46:26
Done.
| |
| 35 void CopyCheckForFileExistenceResult(bool* out, bool value) { | 36 class DownloadHandlerTestFileSystem : public DummyFileSystem { |
| 36 *out = value; | 37 public: |
| 37 } | 38 DownloadHandlerTestFileSystem() : state_(PATH_INVALID) {} |
| 39 | |
| 40 void set_download_path_state(DownloadPathState state) { state_ = state; } | |
| 41 | |
| 42 // FileSystemInterface overrides. | |
| 43 virtual void GetResourceEntryByPath( | |
| 44 const base::FilePath& file_path, | |
| 45 const GetResourceEntryCallback& callback) OVERRIDE { | |
| 46 if (state_ == PATH_EXISTS) { | |
| 47 callback.Run(FILE_ERROR_OK, make_scoped_ptr(new ResourceEntry)); | |
| 48 return; | |
| 49 } | |
| 50 callback.Run( | |
| 51 state_ == PATH_INVALID ? FILE_ERROR_FAILED : FILE_ERROR_NOT_FOUND, | |
| 52 scoped_ptr<ResourceEntry>()); | |
| 53 } | |
| 54 | |
| 55 virtual void CreateDirectory( | |
| 56 const base::FilePath& directory_path, | |
| 57 bool is_exclusive, | |
| 58 bool is_recursive, | |
| 59 const FileOperationCallback& callback) OVERRIDE { | |
| 60 callback.Run(state_ == PATH_NOT_EXIST ? FILE_ERROR_OK : FILE_ERROR_FAILED); | |
| 61 } | |
| 62 | |
| 63 private: | |
| 64 DownloadPathState state_; | |
| 65 }; | |
| 38 | 66 |
| 39 } // namespace | 67 } // namespace |
| 40 | 68 |
| 41 class DownloadHandlerTest : public testing::Test { | 69 class DownloadHandlerTest : public testing::Test { |
| 42 public: | 70 public: |
| 43 DownloadHandlerTest() | 71 DownloadHandlerTest() |
| 44 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 72 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 45 download_manager_(new content::MockDownloadManager) {} | 73 download_manager_(new content::MockDownloadManager) {} |
| 46 | 74 |
| 47 virtual void SetUp() OVERRIDE { | 75 virtual void SetUp() OVERRIDE { |
| 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 76 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 49 | 77 |
| 50 // Set expectations for download item. | 78 // Set expectations for download item. |
| 51 EXPECT_CALL(download_item_, GetState()) | 79 EXPECT_CALL(download_item_, GetState()) |
| 52 .WillRepeatedly(Return(content::DownloadItem::IN_PROGRESS)); | 80 .WillRepeatedly(testing::Return(content::DownloadItem::IN_PROGRESS)); |
|
hashimoto
2013/06/04 00:53:09
nit: Can't we make this line unchanged?
kinaba
2013/06/04 03:46:26
As talked offline, let's keep it in the changed fo
| |
| 53 | 81 |
| 54 // Set expectations for file system to save argument callbacks. | 82 file_write_helper_.reset(new FileWriteHelper(&test_file_system_)); |
| 55 EXPECT_CALL(file_system_, GetResourceEntryByPath(_, _)) | |
| 56 .WillRepeatedly(SaveArg<1>(&get_entry_info_callback_)); | |
| 57 EXPECT_CALL(file_system_, CreateDirectory(_, _, _, _)) | |
| 58 .WillRepeatedly(SaveArg<3>(&create_directory_callback_)); | |
| 59 | |
| 60 file_write_helper_.reset(new FileWriteHelper(&file_system_)); | |
| 61 download_handler_.reset( | 83 download_handler_.reset( |
| 62 new DownloadHandler(file_write_helper_.get(), &file_system_)); | 84 new DownloadHandler(file_write_helper_.get(), &test_file_system_)); |
| 63 download_handler_->Initialize(download_manager_.get(), temp_dir_.path()); | 85 download_handler_->Initialize(download_manager_.get(), temp_dir_.path()); |
| 64 } | 86 } |
| 65 | 87 |
| 66 virtual void TearDown() OVERRIDE { | |
| 67 } | |
| 68 | |
| 69 protected: | 88 protected: |
| 70 base::ScopedTempDir temp_dir_; | 89 base::ScopedTempDir temp_dir_; |
| 71 base::MessageLoopForUI message_loop_; | 90 base::MessageLoopForUI message_loop_; |
| 72 content::TestBrowserThread ui_thread_; | 91 content::TestBrowserThread ui_thread_; |
| 73 scoped_ptr<content::MockDownloadManager> download_manager_; | 92 scoped_ptr<content::MockDownloadManager> download_manager_; |
| 74 MockFileSystem file_system_; | 93 DownloadHandlerTestFileSystem test_file_system_; |
| 75 scoped_ptr<FileWriteHelper> file_write_helper_; | 94 scoped_ptr<FileWriteHelper> file_write_helper_; |
| 76 scoped_ptr<DownloadHandler> download_handler_; | 95 scoped_ptr<DownloadHandler> download_handler_; |
| 77 content::MockDownloadItem download_item_; | 96 content::MockDownloadItem download_item_; |
| 78 | |
| 79 // Argument callbacks passed to the file system. | |
| 80 GetResourceEntryCallback get_entry_info_callback_; | |
| 81 FileOperationCallback create_directory_callback_; | |
| 82 }; | 97 }; |
| 83 | 98 |
| 84 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { | 99 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathNonDrivePath) { |
| 85 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); | 100 const base::FilePath non_drive_path(FILE_PATH_LITERAL("/foo/bar")); |
| 86 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); | 101 ASSERT_FALSE(util::IsUnderDriveMountPoint(non_drive_path)); |
| 87 | 102 |
| 88 // Call SubstituteDriveDownloadPath() | 103 // Call SubstituteDriveDownloadPath() |
| 89 base::FilePath substituted_path; | 104 base::FilePath substituted_path; |
| 90 download_handler_->SubstituteDriveDownloadPath( | 105 download_handler_->SubstituteDriveDownloadPath( |
| 91 non_drive_path, | 106 non_drive_path, |
| 92 &download_item_, | 107 &download_item_, |
| 93 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 108 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 94 google_apis::test_util::RunBlockingPoolTask(); | 109 google_apis::test_util::RunBlockingPoolTask(); |
| 95 | 110 |
| 96 // Check the result. | 111 // Check the result. |
| 97 EXPECT_EQ(non_drive_path, substituted_path); | 112 EXPECT_EQ(non_drive_path, substituted_path); |
| 98 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); | 113 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); |
| 99 } | 114 } |
| 100 | 115 |
| 101 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPath) { | 116 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPath) { |
| 102 const base::FilePath drive_path = | 117 const base::FilePath drive_path = |
| 103 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 118 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 104 | 119 |
| 120 // Test the case that the download target directory already exists. | |
| 121 test_file_system_.set_download_path_state(PATH_EXISTS); | |
| 122 | |
| 105 // Call SubstituteDriveDownloadPath() | 123 // Call SubstituteDriveDownloadPath() |
| 106 base::FilePath substituted_path; | 124 base::FilePath substituted_path; |
| 107 download_handler_->SubstituteDriveDownloadPath( | 125 download_handler_->SubstituteDriveDownloadPath( |
| 108 drive_path, | 126 drive_path, |
| 109 &download_item_, | 127 &download_item_, |
| 110 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 128 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 111 google_apis::test_util::RunBlockingPoolTask(); | |
| 112 | |
| 113 // Return result of GetResourceEntryByPath(), destination directory found. | |
| 114 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | |
| 115 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 116 get_entry_info_callback_.Run(FILE_ERROR_OK, entry.Pass()); | |
| 117 google_apis::test_util::RunBlockingPoolTask(); | 129 google_apis::test_util::RunBlockingPoolTask(); |
| 118 | 130 |
| 119 // Check the result. | 131 // Check the result. |
| 120 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); | 132 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); |
| 121 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); | 133 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); |
| 122 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 134 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 123 } | 135 } |
| 124 | 136 |
| 125 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathGetEntryFailure) { | 137 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathGetEntryFailure) { |
| 126 const base::FilePath drive_path = | 138 const base::FilePath drive_path = |
| 127 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 139 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 128 | 140 |
| 141 // Test the case that access to the download target directory failed for some | |
| 142 // reason. | |
| 143 test_file_system_.set_download_path_state(PATH_INVALID); | |
| 144 | |
| 129 // Call SubstituteDriveDownloadPath() | 145 // Call SubstituteDriveDownloadPath() |
| 130 base::FilePath substituted_path; | 146 base::FilePath substituted_path; |
| 131 download_handler_->SubstituteDriveDownloadPath( | 147 download_handler_->SubstituteDriveDownloadPath( |
| 132 drive_path, | 148 drive_path, |
| 133 &download_item_, | 149 &download_item_, |
| 134 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 150 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 135 google_apis::test_util::RunBlockingPoolTask(); | |
| 136 | |
| 137 // Return result of GetResourceEntryByPath(), failing for some reason. | |
| 138 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 139 get_entry_info_callback_.Run(FILE_ERROR_FAILED, | |
| 140 scoped_ptr<ResourceEntry>()); | |
| 141 google_apis::test_util::RunBlockingPoolTask(); | 151 google_apis::test_util::RunBlockingPoolTask(); |
| 142 | 152 |
| 143 // Check the result. | 153 // Check the result. |
| 144 EXPECT_TRUE(substituted_path.empty()); | 154 EXPECT_TRUE(substituted_path.empty()); |
| 145 } | 155 } |
| 146 | 156 |
| 147 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathCreateDirectory) { | 157 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathCreateDirectory) { |
| 148 const base::FilePath drive_path = | 158 const base::FilePath drive_path = |
| 149 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 159 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 150 | 160 |
| 161 // Test the case that access to the download target directory does not exist, | |
| 162 // and thus will be created in DownloadHandler. | |
| 163 test_file_system_.set_download_path_state(PATH_NOT_EXIST); | |
| 164 | |
| 151 // Call SubstituteDriveDownloadPath() | 165 // Call SubstituteDriveDownloadPath() |
| 152 base::FilePath substituted_path; | 166 base::FilePath substituted_path; |
| 153 download_handler_->SubstituteDriveDownloadPath( | 167 download_handler_->SubstituteDriveDownloadPath( |
| 154 drive_path, | 168 drive_path, |
| 155 &download_item_, | 169 &download_item_, |
| 156 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 170 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 157 google_apis::test_util::RunBlockingPoolTask(); | |
| 158 | |
| 159 // Return result of GetResourceEntryByPath(), destination directory not found. | |
| 160 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 161 get_entry_info_callback_.Run(FILE_ERROR_NOT_FOUND, | |
| 162 scoped_ptr<ResourceEntry>()); | |
| 163 google_apis::test_util::RunBlockingPoolTask(); | |
| 164 | |
| 165 // Return result of CreateDirecotry(). | |
| 166 ASSERT_FALSE(create_directory_callback_.is_null()); | |
| 167 create_directory_callback_.Run(FILE_ERROR_OK); | |
| 168 google_apis::test_util::RunBlockingPoolTask(); | 171 google_apis::test_util::RunBlockingPoolTask(); |
| 169 | 172 |
| 170 // Check the result. | 173 // Check the result. |
| 171 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); | 174 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); |
| 172 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); | 175 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); |
| 173 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 176 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 174 } | 177 } |
| 175 | 178 |
| 176 TEST_F(DownloadHandlerTest, | 179 TEST_F(DownloadHandlerTest, |
| 177 SubstituteDriveDownloadPathCreateDirectoryFailure) { | 180 SubstituteDriveDownloadPathCreateDirectoryFailure) { |
| 178 const base::FilePath drive_path = | 181 const base::FilePath drive_path = |
| 179 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 182 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 180 | 183 |
| 184 // Test the case that access to the download target directory does not exist, | |
| 185 // and creation fails for some reason. | |
| 186 test_file_system_.set_download_path_state(PATH_NOT_EXIST_AND_CREATE_FAIL); | |
| 187 | |
| 181 // Call SubstituteDriveDownloadPath() | 188 // Call SubstituteDriveDownloadPath() |
| 182 base::FilePath substituted_path; | 189 base::FilePath substituted_path; |
| 183 download_handler_->SubstituteDriveDownloadPath( | 190 download_handler_->SubstituteDriveDownloadPath( |
| 184 drive_path, | 191 drive_path, |
| 185 &download_item_, | 192 &download_item_, |
| 186 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 193 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 187 google_apis::test_util::RunBlockingPoolTask(); | |
| 188 | |
| 189 // Return result of GetResourceEntryByPath(), destination directory not found. | |
| 190 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 191 get_entry_info_callback_.Run(FILE_ERROR_NOT_FOUND, | |
| 192 scoped_ptr<ResourceEntry>()); | |
| 193 google_apis::test_util::RunBlockingPoolTask(); | |
| 194 | |
| 195 // Return result of CreateDirecotry(). | |
| 196 ASSERT_FALSE(create_directory_callback_.is_null()); | |
| 197 create_directory_callback_.Run(FILE_ERROR_FAILED); | |
| 198 google_apis::test_util::RunBlockingPoolTask(); | 194 google_apis::test_util::RunBlockingPoolTask(); |
| 199 | 195 |
| 200 // Check the result. | 196 // Check the result. |
| 201 EXPECT_TRUE(substituted_path.empty()); | 197 EXPECT_TRUE(substituted_path.empty()); |
| 202 } | 198 } |
| 203 | 199 |
| 204 // content::SavePackage calls SubstituteDriveDownloadPath before creating | 200 // content::SavePackage calls SubstituteDriveDownloadPath before creating |
| 205 // DownloadItem. | 201 // DownloadItem. |
| 206 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathForSavePackage) { | 202 TEST_F(DownloadHandlerTest, SubstituteDriveDownloadPathForSavePackage) { |
| 207 const base::FilePath drive_path = | 203 const base::FilePath drive_path = |
| 208 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 204 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 205 test_file_system_.set_download_path_state(PATH_EXISTS); | |
| 209 | 206 |
| 210 // Call SubstituteDriveDownloadPath() | 207 // Call SubstituteDriveDownloadPath() |
| 211 base::FilePath substituted_path; | 208 base::FilePath substituted_path; |
| 212 download_handler_->SubstituteDriveDownloadPath( | 209 download_handler_->SubstituteDriveDownloadPath( |
| 213 drive_path, | 210 drive_path, |
| 214 NULL, // DownloadItem is not available at this moment. | 211 NULL, // DownloadItem is not available at this moment. |
| 215 base::Bind(&CopySubstituteDriveDownloadPathResult, &substituted_path)); | 212 google_apis::test_util::CreateCopyResultCallback(&substituted_path)); |
| 216 google_apis::test_util::RunBlockingPoolTask(); | |
| 217 | |
| 218 // Return result of GetResourceEntryByPath(), destination directory found. | |
| 219 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | |
| 220 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 221 get_entry_info_callback_.Run(FILE_ERROR_OK, entry.Pass()); | |
| 222 google_apis::test_util::RunBlockingPoolTask(); | 213 google_apis::test_util::RunBlockingPoolTask(); |
| 223 | 214 |
| 224 // Check the result of SubstituteDriveDownloadPath(). | 215 // Check the result of SubstituteDriveDownloadPath(). |
| 225 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); | 216 EXPECT_TRUE(temp_dir_.path().IsParent(substituted_path)); |
| 226 | 217 |
| 227 // |download_item_| is not a drive download yet. | 218 // |download_item_| is not a drive download yet. |
| 228 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); | 219 EXPECT_FALSE(download_handler_->IsDriveDownload(&download_item_)); |
| 229 | 220 |
| 230 // Call SetDownloadParams(). | 221 // Call SetDownloadParams(). |
| 231 download_handler_->SetDownloadParams(drive_path, &download_item_); | 222 download_handler_->SetDownloadParams(drive_path, &download_item_); |
| 232 | 223 |
| 233 // |download_item_| is a drive download now. | 224 // |download_item_| is a drive download now. |
| 234 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); | 225 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); |
| 235 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 226 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 236 } | 227 } |
| 237 | 228 |
| 238 TEST_F(DownloadHandlerTest, CheckForFileExistence) { | 229 TEST_F(DownloadHandlerTest, CheckForFileExistence) { |
| 239 const base::FilePath drive_path = | 230 const base::FilePath drive_path = |
| 240 util::GetDriveMountPointPath().AppendASCII("test.dat"); | 231 util::GetDriveMountPointPath().AppendASCII("test.dat"); |
| 241 | 232 |
| 242 // Make |download_item_| a drive download. | 233 // Make |download_item_| a drive download. |
| 243 download_handler_->SetDownloadParams(drive_path, &download_item_); | 234 download_handler_->SetDownloadParams(drive_path, &download_item_); |
| 244 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); | 235 ASSERT_TRUE(download_handler_->IsDriveDownload(&download_item_)); |
| 245 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); | 236 EXPECT_EQ(drive_path, download_handler_->GetTargetPath(&download_item_)); |
| 246 | 237 |
| 238 // Test for the case when the path exists. | |
| 239 test_file_system_.set_download_path_state(PATH_EXISTS); | |
| 240 | |
| 247 // Call CheckForFileExistence. | 241 // Call CheckForFileExistence. |
| 248 bool file_exists = false; | 242 bool file_exists = false; |
| 249 download_handler_->CheckForFileExistence( | 243 download_handler_->CheckForFileExistence( |
| 250 &download_item_, | 244 &download_item_, |
| 251 base::Bind(&CopyCheckForFileExistenceResult, &file_exists)); | 245 google_apis::test_util::CreateCopyResultCallback(&file_exists)); |
| 252 google_apis::test_util::RunBlockingPoolTask(); | |
| 253 | |
| 254 // Return result of GetResourceEntryByPath(), file exists. | |
| 255 { | |
| 256 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | |
| 257 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 258 get_entry_info_callback_.Run(FILE_ERROR_OK, entry.Pass()); | |
| 259 } | |
| 260 google_apis::test_util::RunBlockingPoolTask(); | 246 google_apis::test_util::RunBlockingPoolTask(); |
| 261 | 247 |
| 262 // Check the result. | 248 // Check the result. |
| 263 EXPECT_TRUE(file_exists); | 249 EXPECT_TRUE(file_exists); |
| 264 | 250 |
| 265 // Reset callback to call CheckForFileExistence again. | 251 // Test for the case when the path does not exist. |
| 266 get_entry_info_callback_.Reset(); | 252 test_file_system_.set_download_path_state(PATH_NOT_EXIST); |
| 267 | 253 |
| 268 // Call CheckForFileExistence again. | 254 // Call CheckForFileExistence again. |
| 269 download_handler_->CheckForFileExistence( | 255 download_handler_->CheckForFileExistence( |
| 270 &download_item_, | 256 &download_item_, |
| 271 base::Bind(&CopyCheckForFileExistenceResult, &file_exists)); | 257 google_apis::test_util::CreateCopyResultCallback(&file_exists)); |
| 272 google_apis::test_util::RunBlockingPoolTask(); | |
| 273 | |
| 274 // Return result of GetResourceEntryByPath(), file does not exist. | |
| 275 ASSERT_FALSE(get_entry_info_callback_.is_null()); | |
| 276 get_entry_info_callback_.Run(FILE_ERROR_NOT_FOUND, | |
| 277 scoped_ptr<ResourceEntry>()); | |
| 278 google_apis::test_util::RunBlockingPoolTask(); | 258 google_apis::test_util::RunBlockingPoolTask(); |
| 279 | 259 |
| 280 // Check the result. | 260 // Check the result. |
| 281 EXPECT_FALSE(file_exists); | 261 EXPECT_FALSE(file_exists); |
| 282 } | 262 } |
| 283 | 263 |
| 284 } // namespace drive | 264 } // namespace drive |
| OLD | NEW |