| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 base::FilePath ChromeDownloadManagerDelegateTest::GetPathInDownloadDir( | 244 base::FilePath ChromeDownloadManagerDelegateTest::GetPathInDownloadDir( |
| 245 const char* relative_path) { | 245 const char* relative_path) { |
| 246 base::FilePath full_path = | 246 base::FilePath full_path = |
| 247 test_download_dir_.path().AppendASCII(relative_path); | 247 test_download_dir_.path().AppendASCII(relative_path); |
| 248 return full_path.NormalizePathSeparators(); | 248 return full_path.NormalizePathSeparators(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( | 251 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( |
| 252 const base::FilePath& path) { | 252 const base::FilePath& path) { |
| 253 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); | 253 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
| 254 pref_service_->SetFilePath(prefs::kSaveFileDefaultDirectory, path); |
| 254 } | 255 } |
| 255 | 256 |
| 256 void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget( | 257 void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget( |
| 257 DownloadItem* download_item, | 258 DownloadItem* download_item, |
| 258 DownloadTarget* result) { | 259 DownloadTarget* result) { |
| 259 base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this); | 260 base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this); |
| 260 delegate()->DetermineDownloadTarget( | 261 delegate()->DetermineDownloadTarget( |
| 261 download_item, | 262 download_item, |
| 262 base::Bind(&ChromeDownloadManagerDelegateTest::OnDownloadTargetDone, | 263 base::Bind(&ChromeDownloadManagerDelegateTest::OnDownloadTargetDone, |
| 263 factory.GetWeakPtr(), base::Unretained(result))); | 264 factory.GetWeakPtr(), base::Unretained(result))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 293 } | 294 } |
| 294 | 295 |
| 295 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { | 296 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { |
| 296 return delegate_->download_prefs(); | 297 return delegate_->download_prefs(); |
| 297 } | 298 } |
| 298 | 299 |
| 299 } // namespace | 300 } // namespace |
| 300 | 301 |
| 301 TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) { | 302 TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) { |
| 302 GURL download_url("http://example.com/foo.txt"); | 303 GURL download_url("http://example.com/foo.txt"); |
| 303 delegate()->ClearLastDownloadPath(); | |
| 304 | 304 |
| 305 scoped_ptr<content::MockDownloadItem> save_as_download( | 305 scoped_ptr<content::MockDownloadItem> save_as_download( |
| 306 CreateActiveDownloadItem(0)); | 306 CreateActiveDownloadItem(0)); |
| 307 EXPECT_CALL(*save_as_download, GetURL()) | 307 EXPECT_CALL(*save_as_download, GetURL()) |
| 308 .Times(::testing::AnyNumber()) | 308 .Times(::testing::AnyNumber()) |
| 309 .WillRepeatedly(ReturnRef(download_url)); | 309 .WillRepeatedly(ReturnRef(download_url)); |
| 310 EXPECT_CALL(*save_as_download, GetTargetDisposition()) | 310 EXPECT_CALL(*save_as_download, GetTargetDisposition()) |
| 311 .Times(::testing::AnyNumber()) | 311 .Times(::testing::AnyNumber()) |
| 312 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); | 312 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); |
| 313 | 313 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 { | 351 { |
| 352 // Start an automatic download. This one should get the default download | 352 // Start an automatic download. This one should get the default download |
| 353 // path since the last download path only affects Save As downloads. | 353 // path since the last download path only affects Save As downloads. |
| 354 DownloadTarget result; | 354 DownloadTarget result; |
| 355 base::FilePath expected_path(GetPathInDownloadDir("foo.txt")); | 355 base::FilePath expected_path(GetPathInDownloadDir("foo.txt")); |
| 356 DetermineDownloadTarget(automatic_download.get(), &result); | 356 DetermineDownloadTarget(automatic_download.get(), &result); |
| 357 EXPECT_EQ(expected_path, result.target_path); | 357 EXPECT_EQ(expected_path, result.target_path); |
| 358 VerifyAndClearExpectations(); | 358 VerifyAndClearExpectations(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 // Clear the last download path. | |
| 362 delegate()->ClearLastDownloadPath(); | |
| 363 | |
| 364 { | 361 { |
| 365 // The prompt path for the next download should be the default. | 362 // The prompt path for the next download should be the default. |
| 363 download_prefs()->SetSaveFilePath(download_prefs()->DownloadPath()); |
| 366 DownloadTarget result; | 364 DownloadTarget result; |
| 367 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); | 365 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); |
| 368 EXPECT_CALL(*delegate(), | 366 EXPECT_CALL(*delegate(), |
| 369 MockPromptUserForDownloadPath(save_as_download.get(), | 367 MockPromptUserForDownloadPath(save_as_download.get(), |
| 370 expected_prompt_path, _)) | 368 expected_prompt_path, _)) |
| 371 .WillOnce(Return(base::FilePath())); | 369 .WillOnce(Return(base::FilePath())); |
| 372 DetermineDownloadTarget(save_as_download.get(), &result); | 370 DetermineDownloadTarget(save_as_download.get(), &result); |
| 373 VerifyAndClearExpectations(); | 371 VerifyAndClearExpectations(); |
| 374 } | 372 } |
| 375 } | 373 } |
| 374 |
| 375 // TODO(benjhayden): DownloadPrefs::[Set]SaveFilePath() on-the-record vs. off |
| OLD | NEW |