| 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/at_exit.h" | 5 #include "base/at_exit.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 bool create_directory, | 458 bool create_directory, |
| 459 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 459 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 460 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) { | 460 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) { |
| 461 callback.Run(virtual_path, true); | 461 callback.Run(virtual_path, true); |
| 462 } | 462 } |
| 463 | 463 |
| 464 // static | 464 // static |
| 465 void MockDownloadTargetDeterminerDelegate::NullPromptUser( | 465 void MockDownloadTargetDeterminerDelegate::NullPromptUser( |
| 466 DownloadItem* download, const base::FilePath& suggested_path, | 466 DownloadItem* download, const base::FilePath& suggested_path, |
| 467 const FileSelectedCallback& callback) { | 467 const FileSelectedCallback& callback) { |
| 468 callback.Run(suggested_path); | 468 callback.Run(suggested_path, false); |
| 469 } | 469 } |
| 470 | 470 |
| 471 // static | 471 // static |
| 472 void MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath( | 472 void MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath( |
| 473 DownloadItem* download, const base::FilePath& virtual_path, | 473 DownloadItem* download, const base::FilePath& virtual_path, |
| 474 const LocalPathCallback& callback) { | 474 const LocalPathCallback& callback) { |
| 475 callback.Run(virtual_path); | 475 callback.Run(virtual_path); |
| 476 } | 476 } |
| 477 | 477 |
| 478 // NotifyExtensions implementation that overrides the path so that the target | 478 // NotifyExtensions implementation that overrides the path so that the target |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 "http://example.com/foo.txt", "text/plain", | 575 "http://example.com/foo.txt", "text/plain", |
| 576 FILE_PATH_LITERAL(""), | 576 FILE_PATH_LITERAL(""), |
| 577 | 577 |
| 578 FILE_PATH_LITERAL(""), | 578 FILE_PATH_LITERAL(""), |
| 579 DownloadItem::TARGET_DISPOSITION_PROMPT, | 579 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 580 | 580 |
| 581 EXPECT_LOCAL_PATH | 581 EXPECT_LOCAL_PATH |
| 582 } | 582 } |
| 583 }; | 583 }; |
| 584 ON_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)) | 584 ON_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)) |
| 585 .WillByDefault(WithArg<2>(ScheduleCallback(base::FilePath()))); | 585 .WillByDefault(WithArg<2>(ScheduleCallback2(base::FilePath(), false))); |
| 586 RunTestCasesWithActiveItem(kCancelSaveAsTestCases, | 586 RunTestCasesWithActiveItem(kCancelSaveAsTestCases, |
| 587 arraysize(kCancelSaveAsTestCases)); | 587 arraysize(kCancelSaveAsTestCases)); |
| 588 } | 588 } |
| 589 | 589 |
| 590 // The SafeBrowsing check is performed early. Make sure that a download item | 590 // The SafeBrowsing check is performed early. Make sure that a download item |
| 591 // that has been marked as DANGEROUS_URL behaves correctly. | 591 // that has been marked as DANGEROUS_URL behaves correctly. |
| 592 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) { | 592 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) { |
| 593 const DownloadTestCase kSafeBrowsingTestCases[] = { | 593 const DownloadTestCase kSafeBrowsingTestCases[] = { |
| 594 { | 594 { |
| 595 // 0: Automatic Dangerous URL | 595 // 0: Automatic Dangerous URL |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 FILE_PATH_LITERAL("foo-local.txt"), | 870 FILE_PATH_LITERAL("foo-local.txt"), |
| 871 DownloadItem::TARGET_DISPOSITION_PROMPT, | 871 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 872 | 872 |
| 873 EXPECT_LOCAL_PATH | 873 EXPECT_LOCAL_PATH |
| 874 }; | 874 }; |
| 875 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) | 875 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) |
| 876 .WillOnce(WithArg<2>(ScheduleCallback( | 876 .WillOnce(WithArg<2>(ScheduleCallback( |
| 877 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); | 877 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); |
| 878 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( | 878 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( |
| 879 _, test_virtual_dir().AppendASCII("bar.txt"), _)) | 879 _, test_virtual_dir().AppendASCII("bar.txt"), _)) |
| 880 .WillOnce(WithArg<2>(ScheduleCallback( | 880 .WillOnce(WithArg<2>(ScheduleCallback2( |
| 881 test_virtual_dir().AppendASCII("prompted.txt")))); | 881 test_virtual_dir().AppendASCII("prompted.txt"), false))); |
| 882 RunTestCasesWithActiveItem(&kSaveAsToVirtualDir, 1); | 882 RunTestCasesWithActiveItem(&kSaveAsToVirtualDir, 1); |
| 883 } | 883 } |
| 884 | 884 |
| 885 { | 885 { |
| 886 SCOPED_TRACE(testing::Message() << "Save As to local directory"); | 886 SCOPED_TRACE(testing::Message() << "Save As to local directory"); |
| 887 const DownloadTestCase kSaveAsToLocalDir = { | 887 const DownloadTestCase kSaveAsToLocalDir = { |
| 888 SAVE_AS, | 888 SAVE_AS, |
| 889 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 889 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 890 "http://example.com/bar.txt", "text/plain", | 890 "http://example.com/bar.txt", "text/plain", |
| 891 FILE_PATH_LITERAL(""), | 891 FILE_PATH_LITERAL(""), |
| 892 | 892 |
| 893 FILE_PATH_LITERAL("foo-x.txt"), | 893 FILE_PATH_LITERAL("foo-x.txt"), |
| 894 DownloadItem::TARGET_DISPOSITION_PROMPT, | 894 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 895 | 895 |
| 896 EXPECT_CRDOWNLOAD | 896 EXPECT_CRDOWNLOAD |
| 897 }; | 897 }; |
| 898 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( | 898 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( |
| 899 _, test_virtual_dir().AppendASCII("bar.txt"), _)) | 899 _, test_virtual_dir().AppendASCII("bar.txt"), _)) |
| 900 .WillOnce(WithArg<2>(ScheduleCallback( | 900 .WillOnce(WithArg<2>(ScheduleCallback2( |
| 901 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-x.txt"))))); | 901 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-x.txt")), false))); |
| 902 RunTestCasesWithActiveItem(&kSaveAsToLocalDir, 1); | 902 RunTestCasesWithActiveItem(&kSaveAsToLocalDir, 1); |
| 903 } | 903 } |
| 904 | 904 |
| 905 { | 905 { |
| 906 SCOPED_TRACE(testing::Message() << "Forced safe download"); | 906 SCOPED_TRACE(testing::Message() << "Forced safe download"); |
| 907 const DownloadTestCase kForcedSafe = { | 907 const DownloadTestCase kForcedSafe = { |
| 908 FORCED, | 908 FORCED, |
| 909 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 909 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 910 "http://example.com/foo.txt", "", | 910 "http://example.com/foo.txt", "", |
| 911 FILE_PATH_LITERAL("forced-foo.txt"), | 911 FILE_PATH_LITERAL("forced-foo.txt"), |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1426 download_prefs()->SetSaveFilePath(GetPathInDownloadDir( | 1426 download_prefs()->SetSaveFilePath(GetPathInDownloadDir( |
| 1427 FILE_PATH_LITERAL("last_selected"))); | 1427 FILE_PATH_LITERAL("last_selected"))); |
| 1428 | 1428 |
| 1429 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1429 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1430 .WillOnce(WithArg<2>( | 1430 .WillOnce(WithArg<2>( |
| 1431 ScheduleCallback2(overridden_path, | 1431 ScheduleCallback2(overridden_path, |
| 1432 DownloadPathReservationTracker::UNIQUIFY))); | 1432 DownloadPathReservationTracker::UNIQUIFY))); |
| 1433 EXPECT_CALL(*delegate(), | 1433 EXPECT_CALL(*delegate(), |
| 1434 PromptUserForDownloadPath(_, full_overridden_path, _)) | 1434 PromptUserForDownloadPath(_, full_overridden_path, _)) |
| 1435 .WillOnce(WithArg<2>( | 1435 .WillOnce(WithArg<2>( |
| 1436 ScheduleCallback(full_overridden_path))); | 1436 ScheduleCallback2(full_overridden_path, false))); |
| 1437 RunTestCase(test_case, base::FilePath(), item.get()); | 1437 RunTestCase(test_case, base::FilePath(), item.get()); |
| 1438 } | 1438 } |
| 1439 | 1439 |
| 1440 TEST_F(DownloadTargetDeterminerTest, | 1440 TEST_F(DownloadTargetDeterminerTest, |
| 1441 TargetDeterminer_InitialVirtualPathUnsafe) { | 1441 TargetDeterminer_InitialVirtualPathUnsafe) { |
| 1442 const base::FilePath::CharType* kInitialPath = | 1442 const base::FilePath::CharType* kInitialPath = |
| 1443 FILE_PATH_LITERAL("some_path/bar.html"); | 1443 FILE_PATH_LITERAL("some_path/bar.html"); |
| 1444 | 1444 |
| 1445 const DownloadTestCase kInitialPathTestCase = { | 1445 const DownloadTestCase kInitialPathTestCase = { |
| 1446 // 0: Save As Save. The path generated based on the DownloadItem is safe, | 1446 // 0: Save As Save. The path generated based on the DownloadItem is safe, |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2239 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2239 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
| 2240 .WillRepeatedly(Return(true)); | 2240 .WillRepeatedly(Return(true)); |
| 2241 | 2241 |
| 2242 target_info = RunDownloadTargetDeterminer( | 2242 target_info = RunDownloadTargetDeterminer( |
| 2243 GetPathInDownloadDir(kInitialPath), item.get()); | 2243 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2244 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2244 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2245 } | 2245 } |
| 2246 #endif // defined(ENABLE_PLUGINS) | 2246 #endif // defined(ENABLE_PLUGINS) |
| 2247 | 2247 |
| 2248 } // namespace | 2248 } // namespace |
| OLD | NEW |