| 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/file_util.h" | 5 #include "base/file_util.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/message_loop.h" | 8 #include "base/message_loop.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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 for (size_t i = 0; i < test_case_count; ++i) { | 457 for (size_t i = 0; i < test_case_count; ++i) { |
| 458 scoped_ptr<content::MockDownloadItem> item(CreateActiveDownloadItem(i)); | 458 scoped_ptr<content::MockDownloadItem> item(CreateActiveDownloadItem(i)); |
| 459 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 459 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 460 RunTestCaseWithDownloadItem(test_cases[i], item.get()); | 460 RunTestCaseWithDownloadItem(test_cases[i], item.get()); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( | 464 void ChromeDownloadManagerDelegateTest::SetDefaultDownloadPath( |
| 465 const base::FilePath& path) { | 465 const base::FilePath& path) { |
| 466 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); | 466 pref_service_->SetFilePath(prefs::kDownloadDefaultDirectory, path); |
| 467 pref_service_->SetFilePath(prefs::kSaveFileDefaultDirectory, path); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void ChromeDownloadManagerDelegateTest::SetManagedDownloadPath( | 470 void ChromeDownloadManagerDelegateTest::SetManagedDownloadPath( |
| 470 const base::FilePath& path) { | 471 const base::FilePath& path) { |
| 471 pref_service_->SetManagedPref(prefs::kDownloadDefaultDirectory, | 472 pref_service_->SetManagedPref(prefs::kDownloadDefaultDirectory, |
| 472 base::CreateFilePathValue(path)); | 473 base::CreateFilePathValue(path)); |
| 473 } | 474 } |
| 474 | 475 |
| 475 void ChromeDownloadManagerDelegateTest::SetPromptForDownload(bool prompt) { | 476 void ChromeDownloadManagerDelegateTest::SetPromptForDownload(bool prompt) { |
| 476 pref_service_->SetBoolean(prefs::kPromptForDownload, prompt); | 477 pref_service_->SetBoolean(prefs::kPromptForDownload, prompt); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 589 |
| 589 FILE_PATH_LITERAL("forced-foo.txt"), | 590 FILE_PATH_LITERAL("forced-foo.txt"), |
| 590 FILE_PATH_LITERAL(""), | 591 FILE_PATH_LITERAL(""), |
| 591 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 592 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 592 | 593 |
| 593 EXPECT_TARGET_PATH | 594 EXPECT_TARGET_PATH |
| 594 }, | 595 }, |
| 595 | 596 |
| 596 #if defined(FULL_SAFE_BROWSING) | 597 #if defined(FULL_SAFE_BROWSING) |
| 597 // These test cases are only applicable if safe browsing is enabled. Without | 598 // These test cases are only applicable if safe browsing is enabled. Without |
| 598 // it, these are equivalent to FORCED/SAFE and SAFE_AS/SAFE respectively. | 599 // it, these are equivalent to FORCED/SAFE and SAVE_AS/SAFE respectively. |
| 599 { | 600 { |
| 600 // 4: Forced Dangerous. As above. .jar is considered to be one of the file | 601 // 4: Forced Dangerous. As above. .jar is considered to be one of the file |
| 601 // types supportred by safe browsing. | 602 // types supportred by safe browsing. |
| 602 FORCED, | 603 FORCED, |
| 603 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 604 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 604 "http://example.com/foo.exe", "", | 605 "http://example.com/foo.exe", "", |
| 605 FILE_PATH_LITERAL("forced-foo.exe"), | 606 FILE_PATH_LITERAL("forced-foo.exe"), |
| 606 | 607 |
| 607 FILE_PATH_LITERAL("forced-foo.exe"), | 608 FILE_PATH_LITERAL("forced-foo.exe"), |
| 608 FILE_PATH_LITERAL(""), | 609 FILE_PATH_LITERAL(""), |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 FILE_PATH_LITERAL("foo.txt"), | 905 FILE_PATH_LITERAL("foo.txt"), |
| 905 FILE_PATH_LITERAL(""), | 906 FILE_PATH_LITERAL(""), |
| 906 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 907 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 907 | 908 |
| 908 EXPECT_CRDOWNLOAD | 909 EXPECT_CRDOWNLOAD |
| 909 }, | 910 }, |
| 910 }; | 911 }; |
| 911 | 912 |
| 912 RunTestCases(kLastSavePathTestCases, arraysize(kLastSavePathTestCases)); | 913 RunTestCases(kLastSavePathTestCases, arraysize(kLastSavePathTestCases)); |
| 913 | 914 |
| 914 // Now clear the last download path. | |
| 915 delegate()->ClearLastDownloadPath(); | |
| 916 | |
| 917 // Run the first test case again. Since the last download path was cleared, | 915 // Run the first test case again. Since the last download path was cleared, |
| 918 // this test case should behave identically to the first time it was run. | 916 // this test case should behave identically to the first time it was run. |
| 919 RunTestCases(kLastSavePathTestCases, 1); | 917 RunTestCases(kLastSavePathTestCases, 1); |
| 920 } | 918 } |
| 921 | 919 |
| 922 // TODO(asanka): Add more tests. | 920 // TODO(asanka): Add more tests. |
| 923 // * Default download path is not writable. | 921 // * Default download path is not writable. |
| 924 // * Download path doesn't exist. | 922 // * Download path doesn't exist. |
| 925 // * IsDangerousFile(). | 923 // * IsDangerousFile(). |
| 926 // * Filename generation. | 924 // * Filename generation. |
| OLD | NEW |