| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 virtual void PromptUserForDownloadPath( | 108 virtual void PromptUserForDownloadPath( |
| 109 DownloadItem* download, | 109 DownloadItem* download, |
| 110 const base::FilePath& suggested_path, | 110 const base::FilePath& suggested_path, |
| 111 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) | 111 const DownloadTargetDeterminerDelegate::FileSelectedCallback& callback) |
| 112 OVERRIDE { | 112 OVERRIDE { |
| 113 base::FilePath return_path = MockPromptUserForDownloadPath(download, | 113 base::FilePath return_path = MockPromptUserForDownloadPath(download, |
| 114 suggested_path, | 114 suggested_path, |
| 115 callback); | 115 callback); |
| 116 OnDownloadPathSelected(callback, return_path); | 116 callback.Run(return_path); |
| 117 } | 117 } |
| 118 | 118 |
| 119 MOCK_METHOD3( | 119 MOCK_METHOD3( |
| 120 MockPromptUserForDownloadPath, | 120 MockPromptUserForDownloadPath, |
| 121 base::FilePath( | 121 base::FilePath( |
| 122 content::DownloadItem*, | 122 content::DownloadItem*, |
| 123 const base::FilePath&, | 123 const base::FilePath&, |
| 124 const DownloadTargetDeterminerDelegate::FileSelectedCallback&)); | 124 const DownloadTargetDeterminerDelegate::FileSelectedCallback&)); |
| 125 | 125 |
| 126 private: | 126 private: |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 base::FilePath ChromeDownloadManagerDelegateTest::GetPathInDownloadDir( | 242 base::FilePath ChromeDownloadManagerDelegateTest::GetPathInDownloadDir( |
| 243 const char* relative_path) { | 243 const char* relative_path) { |
| 244 base::FilePath full_path = | 244 base::FilePath full_path = |
| 245 test_download_dir_.path().AppendASCII(relative_path); | 245 test_download_dir_.path().AppendASCII(relative_path); |
| 246 return full_path.NormalizePathSeparators(); | 246 return full_path.NormalizePathSeparators(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( | 249 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( |
| 250 const base::FilePath& path) { | 250 const base::FilePath& path) { |
| 251 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); | 251 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
| 252 pref_service_->SetFilePath(prefs::kSaveFileDefaultDirectory, path); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget( | 255 void ChromeDownloadManagerDelegateTest::DetermineDownloadTarget( |
| 255 DownloadItem* download_item, | 256 DownloadItem* download_item, |
| 256 DownloadTarget* result) { | 257 DownloadTarget* result) { |
| 257 base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this); | 258 base::WeakPtrFactory<ChromeDownloadManagerDelegateTest> factory(this); |
| 258 delegate()->DetermineDownloadTarget( | 259 delegate()->DetermineDownloadTarget( |
| 259 download_item, | 260 download_item, |
| 260 base::Bind(&ChromeDownloadManagerDelegateTest::OnDownloadTargetDone, | 261 base::Bind(&ChromeDownloadManagerDelegateTest::OnDownloadTargetDone, |
| 261 factory.GetWeakPtr(), base::Unretained(result))); | 262 factory.GetWeakPtr(), base::Unretained(result))); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 291 } | 292 } |
| 292 | 293 |
| 293 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { | 294 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { |
| 294 return delegate_->download_prefs(); | 295 return delegate_->download_prefs(); |
| 295 } | 296 } |
| 296 | 297 |
| 297 } // namespace | 298 } // namespace |
| 298 | 299 |
| 299 TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) { | 300 TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) { |
| 300 GURL download_url("http://example.com/foo.txt"); | 301 GURL download_url("http://example.com/foo.txt"); |
| 301 delegate()->ClearLastDownloadPath(); | |
| 302 | 302 |
| 303 scoped_ptr<content::MockDownloadItem> save_as_download( | 303 scoped_ptr<content::MockDownloadItem> save_as_download( |
| 304 CreateActiveDownloadItem(0)); | 304 CreateActiveDownloadItem(0)); |
| 305 EXPECT_CALL(*save_as_download, GetURL()) | 305 EXPECT_CALL(*save_as_download, GetURL()) |
| 306 .Times(::testing::AnyNumber()) | 306 .Times(::testing::AnyNumber()) |
| 307 .WillRepeatedly(ReturnRef(download_url)); | 307 .WillRepeatedly(ReturnRef(download_url)); |
| 308 EXPECT_CALL(*save_as_download, GetTargetDisposition()) | 308 EXPECT_CALL(*save_as_download, GetTargetDisposition()) |
| 309 .Times(::testing::AnyNumber()) | 309 .Times(::testing::AnyNumber()) |
| 310 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); | 310 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); |
| 311 | 311 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 { | 349 { |
| 350 // Start an automatic download. This one should get the default download | 350 // Start an automatic download. This one should get the default download |
| 351 // path since the last download path only affects Save As downloads. | 351 // path since the last download path only affects Save As downloads. |
| 352 DownloadTarget result; | 352 DownloadTarget result; |
| 353 base::FilePath expected_path(GetPathInDownloadDir("foo.txt")); | 353 base::FilePath expected_path(GetPathInDownloadDir("foo.txt")); |
| 354 DetermineDownloadTarget(automatic_download.get(), &result); | 354 DetermineDownloadTarget(automatic_download.get(), &result); |
| 355 EXPECT_EQ(expected_path, result.target_path); | 355 EXPECT_EQ(expected_path, result.target_path); |
| 356 VerifyAndClearExpectations(); | 356 VerifyAndClearExpectations(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 // Clear the last download path. | |
| 360 delegate()->ClearLastDownloadPath(); | |
| 361 | |
| 362 { | 359 { |
| 363 // The prompt path for the next download should be the default. | 360 // The prompt path for the next download should be the default. |
| 361 download_prefs()->SetSaveFilePath(download_prefs()->DownloadPath()); |
| 364 DownloadTarget result; | 362 DownloadTarget result; |
| 365 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); | 363 base::FilePath expected_prompt_path(GetPathInDownloadDir("foo.txt")); |
| 366 EXPECT_CALL(*delegate(), | 364 EXPECT_CALL(*delegate(), |
| 367 MockPromptUserForDownloadPath(save_as_download.get(), | 365 MockPromptUserForDownloadPath(save_as_download.get(), |
| 368 expected_prompt_path, _)) | 366 expected_prompt_path, _)) |
| 369 .WillOnce(Return(base::FilePath())); | 367 .WillOnce(Return(base::FilePath())); |
| 370 DetermineDownloadTarget(save_as_download.get(), &result); | 368 DetermineDownloadTarget(save_as_download.get(), &result); |
| 371 VerifyAndClearExpectations(); | 369 VerifyAndClearExpectations(); |
| 372 } | 370 } |
| 373 } | 371 } |
| OLD | NEW |