Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3744)

Unified Diff: chrome/browser/download/download_target_determiner_unittest.cc

Issue 2453633006: [downloads] Move platform specific code out of DownloadTargetDeterminer. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_target_determiner_unittest.cc
diff --git a/chrome/browser/download/download_target_determiner_unittest.cc b/chrome/browser/download/download_target_determiner_unittest.cc
index c69e36168c766f25fbb0b50dcaa36051ff09d47f..4884c09d44ee02f455e26841b04885522176b137 100644
--- a/chrome/browser/download/download_target_determiner_unittest.cc
+++ b/chrome/browser/download/download_target_determiner_unittest.cc
@@ -5,11 +5,15 @@
#include <stddef.h>
#include <stdint.h>
+#include <string>
+#include <vector>
+
#include "base/at_exit.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/location.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/observer_list.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
@@ -19,12 +23,15 @@
#include "base/value_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
+#include "chrome/browser/download/download_confirmation_result.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/download/download_target_determiner.h"
#include "chrome/browser/download/download_target_info.h"
#include "chrome/browser/history/history_service_factory.h"
+#include "chrome/common/features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/safe_browsing/file_type_policies.h"
+#include "chrome/common/safe_browsing/file_type_policies_test_util.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/history/core/browser/history_service.h"
@@ -111,6 +118,8 @@ enum TestCaseExpectIntermediate {
EXPECT_CRDOWNLOAD, // Expect path/to/target.crdownload.
EXPECT_UNCONFIRMED, // Expect path/to/Unconfirmed xxx.crdownload.
EXPECT_LOCAL_PATH, // Expect target path.
+ EXPECT_EMPTY, // Expect empty path. Only for downloads which will be marked
svaldez 2016/10/28 17:29:36 Align comments?
asanka 2016/11/07 19:50:15 Done. The former was what clang-format did on its
+ // interrupted or cancelled.
};
// Typical download test case. Used with
@@ -155,8 +164,10 @@ class MockDownloadTargetDeterminerDelegate
MOCK_METHOD3(NotifyExtensions,
void(content::DownloadItem*, const base::FilePath&,
const NotifyExtensionsCallback&));
- MOCK_METHOD3(PromptUserForDownloadPath,
- void(content::DownloadItem*, const base::FilePath&,
+ MOCK_METHOD4(RequestConfirmation,
+ void(content::DownloadItem*,
+ const base::FilePath&,
+ DownloadConfirmationReason,
const FileSelectedCallback&));
MOCK_METHOD3(DetermineLocalPath,
void(DownloadItem*, const base::FilePath&,
@@ -180,9 +191,9 @@ class MockDownloadTargetDeterminerDelegate
ON_CALL(*this, ReserveVirtualPath(_, _, _, _, _))
.WillByDefault(Invoke(
&MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath));
- ON_CALL(*this, PromptUserForDownloadPath(_, _, _))
- .WillByDefault(Invoke(
- &MockDownloadTargetDeterminerDelegate::NullPromptUser));
+ ON_CALL(*this, RequestConfirmation(_, _, _, _))
+ .WillByDefault(
+ Invoke(&MockDownloadTargetDeterminerDelegate::NullPromptUser));
ON_CALL(*this, DetermineLocalPath(_, _, _))
.WillByDefault(Invoke(
&MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath));
@@ -197,9 +208,10 @@ class MockDownloadTargetDeterminerDelegate
bool create_directory,
DownloadPathReservationTracker::FilenameConflictAction conflict_action,
const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback);
- static void NullPromptUser(
- DownloadItem* download, const base::FilePath& suggested_path,
- const FileSelectedCallback& callback);
+ static void NullPromptUser(DownloadItem* download,
+ const base::FilePath& suggested_path,
+ DownloadConfirmationReason reason,
+ const FileSelectedCallback& callback);
static void NullDetermineLocalPath(
DownloadItem* download, const base::FilePath& virtual_path,
const LocalPathCallback& callback);
@@ -212,7 +224,7 @@ class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness {
void TearDown() override;
// Creates MockDownloadItem and sets up default expectations.
- content::MockDownloadItem* CreateActiveDownloadItem(
+ std::unique_ptr<content::MockDownloadItem> CreateActiveDownloadItem(
int32_t id,
const DownloadTestCase& test_case);
@@ -268,17 +280,15 @@ class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness {
return download_prefs_.get();
}
- // Shortcut
- const FileTypePolicies* Policies() const {
- return FileTypePolicies::GetInstance();
- }
-
private:
+ void SetUpFileTypePolicies();
+
std::unique_ptr<DownloadPrefs> download_prefs_;
::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_;
NullWebContentsDelegate web_contents_delegate_;
base::ScopedTempDir test_download_dir_;
base::FilePath test_virtual_dir_;
+ safe_browsing::FileTypePoliciesTestOverlay file_type_configuration_;
};
void DownloadTargetDeterminerTest::SetUp() {
@@ -290,6 +300,7 @@ void DownloadTargetDeterminerTest::SetUp() {
test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual"));
download_prefs_->SetDownloadPath(test_download_dir());
delegate_.SetupDefaults();
+ SetUpFileTypePolicies();
}
void DownloadTargetDeterminerTest::TearDown() {
@@ -297,12 +308,12 @@ void DownloadTargetDeterminerTest::TearDown() {
ChromeRenderViewHostTestHarness::TearDown();
}
-content::MockDownloadItem*
+std::unique_ptr<content::MockDownloadItem>
DownloadTargetDeterminerTest::CreateActiveDownloadItem(
int32_t id,
const DownloadTestCase& test_case) {
- content::MockDownloadItem* item =
- new ::testing::NiceMock<content::MockDownloadItem>();
+ std::unique_ptr<content::MockDownloadItem> item =
+ base::MakeUnique<::testing::NiceMock<content::MockDownloadItem>>();
GURL download_url(test_case.url);
std::vector<GURL> url_chain;
url_chain.push_back(download_url);
@@ -405,9 +416,9 @@ DownloadTargetDeterminerTest::RunDownloadTargetDeterminer(
std::unique_ptr<DownloadTargetInfo> target_info;
base::RunLoop run_loop;
DownloadTargetDeterminer::Start(
- item, initial_virtual_path, download_prefs_.get(), delegate(),
- base::Bind(&CompletionCallbackWrapper,
- run_loop.QuitClosure(),
+ item, initial_virtual_path, DownloadPathReservationTracker::UNIQUIFY,
+ download_prefs_.get(), delegate(),
+ base::Bind(&CompletionCallbackWrapper, run_loop.QuitClosure(),
&target_info));
run_loop.Run();
::testing::Mock::VerifyAndClearExpectations(delegate());
@@ -418,8 +429,8 @@ void DownloadTargetDeterminerTest::RunTestCasesWithActiveItem(
const DownloadTestCase test_cases[],
size_t test_case_count) {
for (size_t i = 0; i < test_case_count; ++i) {
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_cases[i]));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_cases[i]);
SCOPED_TRACE(testing::Message() << "Running test case " << i);
RunTestCase(test_cases[i], base::FilePath(), item.get());
}
@@ -465,9 +476,39 @@ void DownloadTargetDeterminerTest::VerifyDownloadTarget(
EXPECT_EQ(expected_local_path.value(),
target_info->intermediate_path.value());
break;
+
+ case EXPECT_EMPTY:
+ EXPECT_TRUE(target_info->intermediate_path.empty());
+ break;
}
}
+void DownloadTargetDeterminerTest::SetUpFileTypePolicies() {
+ std::unique_ptr<safe_browsing::DownloadFileTypeConfig> fake_file_type_config =
+ base::MakeUnique<safe_browsing::DownloadFileTypeConfig>();
+ auto file_type = fake_file_type_config->mutable_default_file_type();
+ file_type->set_uma_value(-1);
+ auto platform_settings = file_type->add_platform_settings();
+ platform_settings->set_danger_level(DownloadFileType::NOT_DANGEROUS);
+ platform_settings->set_auto_open_hint(DownloadFileType::ALLOW_AUTO_OPEN);
+
+ file_type = fake_file_type_config->add_file_types();
+ file_type->set_extension("kindabad");
+ file_type->set_uma_value(-1);
+ platform_settings = file_type->add_platform_settings();
+ platform_settings->set_danger_level(DownloadFileType::ALLOW_ON_USER_GESTURE);
+ platform_settings->set_auto_open_hint(DownloadFileType::ALLOW_AUTO_OPEN);
+
+ file_type = fake_file_type_config->add_file_types();
+ file_type->set_extension("bad");
+ file_type->set_uma_value(-1);
+ platform_settings = file_type->add_platform_settings();
+ platform_settings->set_danger_level(DownloadFileType::DANGEROUS);
+ platform_settings->set_auto_open_hint(DownloadFileType::DISALLOW_AUTO_OPEN);
+
+ file_type_configuration_.SwapConfig(fake_file_type_config);
+}
+
// static
void MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath(
DownloadItem* download,
@@ -475,14 +516,16 @@ void MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath(
bool create_directory,
DownloadPathReservationTracker::FilenameConflictAction conflict_action,
const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) {
- callback.Run(virtual_path, true);
+ callback.Run(virtual_path, DownloadTargetResult::SUCCESS);
}
// static
void MockDownloadTargetDeterminerDelegate::NullPromptUser(
- DownloadItem* download, const base::FilePath& suggested_path,
+ DownloadItem* download,
+ const base::FilePath& suggested_path,
+ DownloadConfirmationReason reason,
const FileSelectedCallback& callback) {
- callback.Run(suggested_path);
+ callback.Run(DownloadConfirmationResult::CONFIRMED, suggested_path);
}
// static
@@ -509,9 +552,9 @@ void NotifyExtensionsOverridePath(
callback.Run(new_path, DownloadPathReservationTracker::UNIQUIFY);
}
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_Basic) {
+TEST_F(DownloadTargetDeterminerTest, Basic) {
const DownloadTestCase kBasicTestCases[] = {
- {// 0: Automatic Safe
+ {// Automatic Safe
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
"text/plain", FILE_PATH_LITERAL(""),
@@ -520,8 +563,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_Basic) {
EXPECT_CRDOWNLOAD},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
- {// 1: Save_As Safe
+ {// Save_As Safe
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
"text/plain", FILE_PATH_LITERAL(""),
@@ -529,18 +571,18 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_Basic) {
FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_CRDOWNLOAD},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
- {// 2: Automatic Dangerous
+ {// Automatic Dangerous
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx",
- "", FILE_PATH_LITERAL(""),
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
- {// 3: Forced Safe
+ {// Forced Safe
FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "",
FILE_PATH_LITERAL("forced-foo.txt"),
@@ -551,16 +593,15 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_Basic) {
EXPECT_LOCAL_PATH},
};
- // The test assumes that .crx files have a danger level of
+ // The test assumes that .kindabad files have a danger level of
// ALLOW_ON_USER_GESTURE.
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
RunTestCasesWithActiveItem(kBasicTestCases, arraysize(kBasicTestCases));
}
-#if !BUILDFLAG(ANDROID_JAVA_UI)
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_CancelSaveAs) {
+TEST_F(DownloadTargetDeterminerTest, CancelSaveAs) {
const DownloadTestCase kCancelSaveAsTestCases[] = {
{// 0: Save_As Safe, Cancelled.
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
@@ -570,16 +611,16 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_CancelSaveAs) {
FILE_PATH_LITERAL(""), DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_LOCAL_PATH}};
- ON_CALL(*delegate(), PromptUserForDownloadPath(_, _, _))
- .WillByDefault(WithArg<2>(ScheduleCallback(base::FilePath())));
+ ON_CALL(*delegate(), RequestConfirmation(_, _, _, _))
+ .WillByDefault(WithArg<3>(ScheduleCallback2(
+ DownloadConfirmationResult::CANCELED, base::FilePath())));
RunTestCasesWithActiveItem(kCancelSaveAsTestCases,
arraysize(kCancelSaveAsTestCases));
}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
// The SafeBrowsing check is performed early. Make sure that a download item
// that has been marked as DANGEROUS_URL behaves correctly.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
+TEST_F(DownloadTargetDeterminerTest, DangerousUrl) {
const DownloadTestCase kSafeBrowsingTestCases[] = {
{// 0: Automatic Dangerous URL
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
@@ -590,7 +631,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
EXPECT_UNCONFIRMED},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{// 1: Save As Dangerous URL
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt",
@@ -599,7 +639,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_UNCONFIRMED},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{// 2: Forced Dangerous URL
FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
@@ -622,7 +661,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
EXPECT_UNCONFIRMED},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{// 4: Save As Dangerous URL + Dangerous file
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html",
@@ -631,7 +669,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
FILE_PATH_LITERAL("foo.html"), DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_UNCONFIRMED},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{// 5: Forced Dangerous URL + Dangerous file
FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL,
@@ -653,44 +690,44 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) {
// The SafeBrowsing check is performed early. Make sure that a download item
// that has been marked as MAYBE_DANGEROUS_CONTENT behaves correctly.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_MaybeDangerousContent) {
+TEST_F(DownloadTargetDeterminerTest, MaybeDangerousContent) {
const DownloadTestCase kSafeBrowsingTestCases[] = {
{// 0: Automatic Maybe dangerous content
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
DownloadFileType::ALLOW_ON_USER_GESTURE,
- "http://phishing.example.com/foo.crx", "", FILE_PATH_LITERAL(""),
+ "http://phishing.example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
{// 1: Automatic Maybe dangerous content with DANGEROUS type.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
- DownloadFileType::DANGEROUS, "http://phishing.example.com/foo.swf", "",
+ DownloadFileType::DANGEROUS, "http://phishing.example.com/foo.bad", "",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.swf"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.bad"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
-
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{// 2: Save As Maybe dangerous content
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
- DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.crx",
- "", FILE_PATH_LITERAL(""),
+ DownloadFileType::NOT_DANGEROUS,
+ "http://phishing.example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_PROMPT,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_UNCONFIRMED},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{// 3: Forced Maybe dangerous content
FORCED, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
- DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.crx",
- "", FILE_PATH_LITERAL("forced-foo.crx"),
+ DownloadFileType::NOT_DANGEROUS,
+ "http://phishing.example.com/foo.kindabad", "",
+ FILE_PATH_LITERAL("forced-foo.kindabad"),
- FILE_PATH_LITERAL("forced-foo.crx"),
+ FILE_PATH_LITERAL("forced-foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
@@ -698,11 +735,11 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_MaybeDangerousContent) {
// Test assumptions:
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
ASSERT_EQ(DownloadFileType::DANGEROUS,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.swf"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.bad"))));
ON_CALL(*delegate(), CheckDownloadUrl(_, _, _))
.WillByDefault(WithArg<2>(ScheduleCallback(
@@ -711,9 +748,8 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_MaybeDangerousContent) {
arraysize(kSafeBrowsingTestCases));
}
-#if !BUILDFLAG(ANDROID_JAVA_UI)
// Test whether the last saved directory is used for 'Save As' downloads.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) {
+TEST_F(DownloadTargetDeterminerTest, LastSavePath) {
const DownloadTestCase kLastSavePathTestCasesPre[] = {
{// 0: If the last save path is empty, then the default download directory
// should be used.
@@ -767,7 +803,9 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) {
<< "Running with default download path");
base::FilePath prompt_path =
GetPathInDownloadDir(FILE_PATH_LITERAL("foo.txt"));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, prompt_path, _));
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(_, prompt_path,
+ DownloadConfirmationReason::SAVE_AS, _));
RunTestCasesWithActiveItem(kLastSavePathTestCasesPre,
arraysize(kLastSavePathTestCasesPre));
}
@@ -779,7 +817,9 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) {
download_prefs()->SetSaveFilePath(test_download_dir().AppendASCII("foo"));
base::FilePath prompt_path =
GetPathInDownloadDir(FILE_PATH_LITERAL("foo/foo.txt"));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, prompt_path, _));
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(_, prompt_path,
+ DownloadConfirmationReason::SAVE_AS, _));
RunTestCasesWithActiveItem(kLastSavePathTestCasesPost,
arraysize(kLastSavePathTestCasesPost));
}
@@ -791,8 +831,9 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) {
base::FilePath last_selected_dir = test_virtual_dir().AppendASCII("foo");
base::FilePath virtual_path = last_selected_dir.AppendASCII("foo.txt");
download_prefs()->SetSaveFilePath(last_selected_dir);
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(
- _, last_selected_dir.AppendASCII("foo.txt"), _));
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(_, last_selected_dir.AppendASCII("foo.txt"),
+ DownloadConfirmationReason::SAVE_AS, _));
EXPECT_CALL(*delegate(), DetermineLocalPath(_, virtual_path, _))
.WillOnce(WithArg<2>(ScheduleCallback(
GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt")))));
@@ -800,11 +841,10 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) {
arraysize(kLastSavePathTestCasesVirtual));
}
}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
// These tests are run with the default downloads folder set to a virtual
// directory.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) {
+TEST_F(DownloadTargetDeterminerTest, DefaultVirtual) {
// The default download directory is the virutal path.
download_prefs()->SetDownloadPath(test_virtual_dir());
@@ -828,7 +868,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) {
RunTestCasesWithActiveItem(&kAutomaticDownloadToVirtualDir, 1);
}
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{
SCOPED_TRACE(testing::Message() << "Save As to virtual directory");
const DownloadTestCase kSaveAsToVirtualDir = {
@@ -846,13 +885,16 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) {
EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _))
.WillOnce(WithArg<2>(ScheduleCallback(
GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt")))));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(
- _, test_virtual_dir().AppendASCII("bar.txt"), _))
- .WillOnce(WithArg<2>(ScheduleCallback(
- test_virtual_dir().AppendASCII("prompted.txt"))));
+ EXPECT_CALL(*delegate(), RequestConfirmation(
+ _, test_virtual_dir().AppendASCII("bar.txt"),
+ DownloadConfirmationReason::SAVE_AS, _))
+ .WillOnce(WithArg<3>(
+ ScheduleCallback2(DownloadConfirmationResult::CONFIRMED,
+ test_virtual_dir().AppendASCII("prompted.txt"))));
RunTestCasesWithActiveItem(&kSaveAsToVirtualDir, 1);
}
+ // "Save as" is not supported on Android.
svaldez 2016/10/28 17:29:36 Should this move up one test?
asanka 2016/11/07 19:50:15 Should be removed. At the DTD layer, Android deals
{
SCOPED_TRACE(testing::Message() << "Save As to local directory");
const DownloadTestCase kSaveAsToLocalDir = {
@@ -867,13 +909,14 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) {
DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_CRDOWNLOAD};
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(
- _, test_virtual_dir().AppendASCII("bar.txt"), _))
- .WillOnce(WithArg<2>(ScheduleCallback(
+ EXPECT_CALL(*delegate(), RequestConfirmation(
+ _, test_virtual_dir().AppendASCII("bar.txt"),
+ DownloadConfirmationReason::SAVE_AS, _))
+ .WillOnce(WithArg<3>(ScheduleCallback2(
+ DownloadConfirmationResult::CONFIRMED,
GetPathInDownloadDir(FILE_PATH_LITERAL("foo-x.txt")))));
RunTestCasesWithActiveItem(&kSaveAsToLocalDir, 1);
}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{
SCOPED_TRACE(testing::Message() << "Forced safe download");
@@ -895,7 +938,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) {
// Test that an inactive download will still get a virtual or local download
// path.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_InactiveDownload) {
+TEST_F(DownloadTargetDeterminerTest, InactiveDownload) {
const DownloadTestCase kInactiveTestCases[] = {
{AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
@@ -905,26 +948,23 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_InactiveDownload) {
EXPECT_CRDOWNLOAD},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
"text/plain", FILE_PATH_LITERAL(""),
FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
- EXPECT_CRDOWNLOAD}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
- };
+ EXPECT_CRDOWNLOAD}};
svaldez 2016/10/28 17:29:36 Extra whitespace?
asanka 2016/11/07 19:50:15 Reformatted.
for (size_t i = 0; i < arraysize(kInactiveTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "Running test case " << i);
const DownloadTestCase& test_case = kInactiveTestCases[i];
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_case);
EXPECT_CALL(*item.get(), GetState())
.WillRepeatedly(Return(content::DownloadItem::CANCELLED));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)).Times(0);
+ EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0);
EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)).Times(0);
EXPECT_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _)).Times(0);
EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)).Times(1);
@@ -932,31 +972,113 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_InactiveDownload) {
}
}
+namespace {
+
+// TODO(asanka): Once we can use C++14, make this a constexpr and use
+// static_assert where ASSERT* is used. Once we can use C++17 switch to using
+// reflection.
+size_t CountDownloadTargetResultValues() {
svaldez 2016/10/28 17:29:36 Seems excessive since if we forget to add a test c
asanka 2016/11/07 19:50:15 This one fails to compile if we forget to add an e
+ size_t count = 0;
+ DownloadTargetResult result = DownloadTargetResult::SUCCESS;
+ switch (result) {
+ case DownloadTargetResult::SUCCESS:
+ count++;
+ case DownloadTargetResult::USER_CANCELED:
+ count++;
+ case DownloadTargetResult::UNEXPECTED:
+ count++;
+ case DownloadTargetResult::NAME_TOO_LONG:
+ count++;
+ case DownloadTargetResult::CONFLICT:
+ count++;
+ case DownloadTargetResult::PATH_NOT_WRITEABLE:
+ count++;
+ // Oh you added a new |DownloadTargetResult| type? Add a case here for
+ // your new value and increment |count|. Don't forget to update the tests
+ // below. If not, the try bots will remind you.
+ }
+ return count;
+}
+
+} // namespace
+
// If the reserved path could not be verified, then the user should see a
// prompt.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ReservationFailed) {
- const DownloadTestCase kReservationFailedCases[] = {
- {// 0: Automatic download. Since the reservation fails, the disposition of
- // the target is to prompt, but the returned path is used.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
- "text/plain", FILE_PATH_LITERAL(""),
+TEST_F(DownloadTargetDeterminerTest, ReservationFailed_Confirmation) {
+ DownloadTestCase download_test_case = {
+ // 0: Automatic download. Since the reservation fails, the disposition of
+ // the target is to prompt, but the returned path is used.
+ AUTOMATIC,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/foo.txt",
+ "text/plain",
+ FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("bar.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
+ FILE_PATH_LITERAL("bar.txt"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
- EXPECT_CRDOWNLOAD},
+ EXPECT_CRDOWNLOAD};
+
+ struct {
+ DownloadTargetResult result;
+ DownloadConfirmationReason expected_confirmation_reason;
+ } kTestCases[] = {
+ // Reservation succeeded. No confirmation needed.
+ {DownloadTargetResult::SUCCESS, DownloadConfirmationReason::NONE},
+
+ // User cancelled the reservation. No further confirmation needed.
+ {DownloadTargetResult::USER_CANCELED, DownloadConfirmationReason::NONE},
+
+ // An unexpected error occurred. The download will be marked as
+ // interrupted. No confirmation needed.
+ {DownloadTargetResult::UNEXPECTED, DownloadConfirmationReason::NONE},
+
+ // The name was too long. Need to confirm with user.
+ {DownloadTargetResult::NAME_TOO_LONG,
+ DownloadConfirmationReason::NAME_TOO_LONG},
+
+ // Pathname conflict. User confirmation needed.
+ {DownloadTargetResult::CONFLICT,
+ DownloadConfirmationReason::TARGET_CONFLICT},
+
+ // The path is not writeable. Prompt user for a new path.
+ {DownloadTargetResult::PATH_NOT_WRITEABLE,
+ DownloadConfirmationReason::TARGET_NOT_WRITEABLE},
};
- // Setup ReserveVirtualPath() to fail.
- ON_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _))
- .WillByDefault(WithArg<4>(ScheduleCallback2(
- GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt")), false)));
- RunTestCasesWithActiveItem(kReservationFailedCases,
- arraysize(kReservationFailedCases));
+ ASSERT_EQ(CountDownloadTargetResultValues(), arraysize(kTestCases))
svaldez 2016/10/28 17:29:36 This seems kind of fragile. Maybe something like:
asanka 2016/11/07 19:50:15 Hmm. I tried something like that here. Better?
+ << "All enumeration values for DownloadTargetResult must be tested";
+
+ for (auto& test_case : kTestCases) {
+ SCOPED_TRACE(::testing::Message() << "DownloadTargetResult "
+ << static_cast<int>(test_case.result));
+ ON_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _))
+ .WillByDefault(WithArg<4>(ScheduleCallback2(
+ GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt")),
+ test_case.result)));
+ if (test_case.expected_confirmation_reason !=
+ DownloadConfirmationReason::NONE) {
+ EXPECT_CALL(
+ *delegate(),
+ RequestConfirmation(_, _, test_case.expected_confirmation_reason, _));
+ } else {
+ EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0);
+ }
+
+ download_test_case.expected_disposition =
+ test_case.expected_confirmation_reason ==
+ DownloadConfirmationReason::NONE
+ ? content::DownloadItem::TARGET_DISPOSITION_OVERWRITE
+ : content::DownloadItem::TARGET_DISPOSITION_PROMPT;
+ std::unique_ptr<content::MockDownloadItem> item = CreateActiveDownloadItem(
+ static_cast<int>(test_case.result), download_test_case);
+ RunTestCase(download_test_case, base::FilePath(), item.get());
+ }
}
// If the local path could not be determined, the download should be cancelled.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LocalPathFailed) {
+TEST_F(DownloadTargetDeterminerTest, LocalPathFailed) {
const DownloadTestCase kLocalPathFailedCases[] = {
{// 0: Automatic download.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
@@ -981,57 +1103,60 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LocalPathFailed) {
// Downloads that have a danger level of ALLOW_ON_USER_GESTURE should be marked
// as safe depending on whether there was a user gesture associated with the
// download and whether the referrer was visited prior to today.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_VisitedReferrer) {
+TEST_F(DownloadTargetDeterminerTest, VisitedReferrer) {
const DownloadTestCase kVisitedReferrerCases[] = {
// http://visited.example.com/ is added to the history as a visit that
// happened prior to today.
{// 0: Safe download due to visiting referrer before.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://visited.example.com/foo.crx",
- "application/xml", FILE_PATH_LITERAL(""),
+ DownloadFileType::NOT_DANGEROUS,
+ "http://visited.example.com/foo.kindabad", "application/xml",
+ FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_CRDOWNLOAD},
{// 1: Dangerous due to not having visited referrer before.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
DownloadFileType::ALLOW_ON_USER_GESTURE,
- "http://not-visited.example.com/foo.crx", "application/xml",
+ "http://not-visited.example.com/foo.kindabad", "application/xml",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{// 2: Safe because the user is being prompted.
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS,
- "http://not-visited.example.com/foo.crx", "application/xml",
+ "http://not-visited.example.com/foo.kindabad", "application/xml",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_PROMPT,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_CRDOWNLOAD},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{// 3: Safe because of forced path.
FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS,
- "http://not-visited.example.com/foo.crx", "application/xml",
- FILE_PATH_LITERAL("foo.crx"),
+ "http://not-visited.example.com/foo.kindabad", "application/xml",
+ FILE_PATH_LITERAL("foo.kindabad"),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_LOCAL_PATH},
};
- // This test assumes that the danger level of .crx files is
+ // This test assumes that the danger level of .kindabad files is
// ALLOW_ON_USER_GESTURE.
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
// First the history service must exist.
ASSERT_TRUE(profile()->CreateHistoryService(false, false));
@@ -1069,11 +1194,11 @@ TEST_F(DownloadTargetDeterminerTest, TransitionType) {
AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
DownloadFileType::ALLOW_ON_USER_GESTURE,
- "http://example.com/foo.crx",
+ "http://example.com/foo.kindabad",
"application/octet-stream",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"),
+ FILE_PATH_LITERAL("foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED};
@@ -1082,11 +1207,11 @@ TEST_F(DownloadTargetDeterminerTest, TransitionType) {
AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
DownloadFileType::DANGEROUS,
- "http://example.com/foo.swf",
+ "http://example.com/foo.bad",
"application/octet-stream",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.swf"),
+ FILE_PATH_LITERAL("foo.bad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED};
@@ -1139,13 +1264,13 @@ TEST_F(DownloadTargetDeterminerTest, TransitionType) {
// Test assumptions:
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
ASSERT_EQ(DownloadFileType::DANGEROUS,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.swf"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.bad"))));
ASSERT_EQ(DownloadFileType::NOT_DANGEROUS,
- Policies()->GetFileDangerLevel(
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
base::FilePath(FILE_PATH_LITERAL("foo.txt"))));
for (const auto& test_case : kTestCases) {
@@ -1162,98 +1287,186 @@ TEST_F(DownloadTargetDeterminerTest, TransitionType) {
download_test_case.expected_intermediate = EXPECT_CRDOWNLOAD;
}
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(1, download_test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(1, download_test_case);
EXPECT_CALL(*item, GetTransitionType())
.WillRepeatedly(Return(test_case.page_transition));
RunTestCase(download_test_case, base::FilePath(), item.get());
}
}
-#if !BUILDFLAG(ANDROID_JAVA_UI)
// These test cases are run with "Prompt for download" user preference set to
// true.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways) {
- const DownloadTestCase kPromptingTestCases[] = {
- {// 0: Safe Automatic - Should prompt because of "Prompt for download"
- // preference setting.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
- "text/plain", FILE_PATH_LITERAL(""),
+TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeAutomatic) {
+ const DownloadTestCase kSafeAutomatic = {
+ // 0: Safe Automatic - Should prompt because of "Prompt for download"
+ // preference setting.
+ AUTOMATIC,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/automatic.txt",
+ "text/plain",
+ FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
+ FILE_PATH_LITERAL("automatic.txt"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
- EXPECT_CRDOWNLOAD},
+ EXPECT_CRDOWNLOAD};
- {// 1: Safe Forced - Shouldn't prompt.
- FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
- "text/plain", FILE_PATH_LITERAL("foo.txt"),
+ SetPromptForDownload(true);
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(
+ _, GetPathInDownloadDir(FILE_PATH_LITERAL("automatic.txt")),
+ DownloadConfirmationReason::PREFERENCE, _));
+ RunTestCasesWithActiveItem(&kSafeAutomatic, 1);
+}
- FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeSaveAs) {
+ const DownloadTestCase kSafeSaveAs = {
+ // 1: Safe Save As - Should prompt because of "Save as" invocation.
+ SAVE_AS,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/save-as.txt",
+ "text/plain",
+ FILE_PATH_LITERAL(""),
- EXPECT_LOCAL_PATH},
+ FILE_PATH_LITERAL("save-as.txt"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
- {// 2: Automatic - The filename extension is marked as one that we will
- // open automatically. Shouldn't prompt.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.dummy", "",
- FILE_PATH_LITERAL(""),
+ EXPECT_CRDOWNLOAD};
- FILE_PATH_LITERAL("foo.dummy"),
- DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ SetPromptForDownload(true);
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(
+ _, GetPathInDownloadDir(FILE_PATH_LITERAL("save-as.txt")),
+ DownloadConfirmationReason::SAVE_AS, _));
+ RunTestCasesWithActiveItem(&kSafeSaveAs, 1);
+}
- EXPECT_CRDOWNLOAD},
- };
+TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeForced) {
+ const DownloadTestCase kSafeForced = {
+ // 2: Safe Forced - Shouldn't prompt.
+ FORCED,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/foo.txt",
+ "text/plain",
+ FILE_PATH_LITERAL("foo.txt"),
+
+ FILE_PATH_LITERAL("foo.txt"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+
+ EXPECT_LOCAL_PATH};
SetPromptForDownload(true);
+ RunTestCasesWithActiveItem(&kSafeForced, 1);
+}
+
+TEST_F(DownloadTargetDeterminerTest, PromptAlways_AutoOpen) {
+ const DownloadTestCase kAutoOpen = {
+ // 3: Automatic - The filename extension is marked as one that we will
+ // open automatically. Shouldn't prompt.
+ AUTOMATIC,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/foo.dummy",
+ "",
+ FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.dummy"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+
+ EXPECT_CRDOWNLOAD};
+ SetPromptForDownload(true);
EnableAutoOpenBasedOnExtension(
base::FilePath(FILE_PATH_LITERAL("dummy.dummy")));
- RunTestCasesWithActiveItem(kPromptingTestCases,
- arraysize(kPromptingTestCases));
+ RunTestCasesWithActiveItem(&kAutoOpen, 1);
+}
+
+// If an embedder responds to a RequestConfirmation with a new path and a
+// CONTINUE_WITHOUT_CONFIRMATION, then we shouldn't consider the file as safe.
+TEST_F(DownloadTargetDeterminerTest, ContinueWithoutConfirmation_SaveAs) {
+ const DownloadTestCase kTestCase = {
+ SAVE_AS,
+ content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/save-as.kindabad",
+ "text/plain",
+ FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+
+ EXPECT_UNCONFIRMED};
+
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(_, GetPathInDownloadDir(
+ FILE_PATH_LITERAL("save-as.kindabad")),
+ DownloadConfirmationReason::SAVE_AS, _))
+ .WillOnce(WithArg<3>(ScheduleCallback2(
+ DownloadConfirmationResult::CONTINUE_WITHOUT_CONFIRMATION,
+ GetPathInDownloadDir(FILE_PATH_LITERAL("foo.kindabad")))));
+ RunTestCasesWithActiveItem(&kTestCase, 1);
+}
+
+// Same as ContinueWithoutConfirmation_SaveAs, but the embedder response
+// indicates that the user confirmed the path. Hence the danger level of the
+// download and the disposition should be updated accordingly.
+TEST_F(DownloadTargetDeterminerTest, ContinueWithConfirmation_SaveAs) {
+ const DownloadTestCase kTestCase = {
+ SAVE_AS,
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS,
+ "http://example.com/save-as.kindabad",
+ "text/plain",
+ FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_PROMPT,
+
+ EXPECT_CRDOWNLOAD};
+
+ EXPECT_CALL(*delegate(),
+ RequestConfirmation(_, GetPathInDownloadDir(
+ FILE_PATH_LITERAL("save-as.kindabad")),
+ DownloadConfirmationReason::SAVE_AS, _))
+ .WillOnce(WithArg<3>(ScheduleCallback2(
+ DownloadConfirmationResult::CONFIRMED,
+ GetPathInDownloadDir(FILE_PATH_LITERAL("foo.kindabad")))));
+ RunTestCasesWithActiveItem(&kTestCase, 1);
}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
#if defined(ENABLE_EXTENSIONS)
// These test cases are run with "Prompt for download" user preference set to
// true. Automatic extension downloads shouldn't cause prompting.
// Android doesn't support extensions.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) {
+TEST_F(DownloadTargetDeterminerTest, PromptAlways_Extension) {
const DownloadTestCase kPromptingTestCases[] = {
- {// 0: Automatic Browser Extension download. - Shouldn't prompt for browser
- // extension downloads even if "Prompt for download" preference is set.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx",
- extensions::Extension::kMimeType, FILE_PATH_LITERAL(""),
-
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
-
- EXPECT_UNCONFIRMED},
-
-#if defined(OS_WIN)
- {// 1: Automatic User Script - Shouldn't prompt for user script downloads
- // even if "Prompt for download" preference is set. ".js" files are
- // considered dangerous on Windows.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.user.js", "",
- FILE_PATH_LITERAL(""),
-
- FILE_PATH_LITERAL("foo.user.js"),
- DownloadItem::TARGET_DISPOSITION_OVERWRITE,
-
- EXPECT_UNCONFIRMED},
-#else
- {// 1: Automatic User Script - Shouldn't prompt for user script downloads
- // even if "Prompt for download" preference is set.
- AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.user.js", "",
- FILE_PATH_LITERAL(""),
-
- FILE_PATH_LITERAL("foo.user.js"),
- DownloadItem::TARGET_DISPOSITION_OVERWRITE,
-
- EXPECT_CRDOWNLOAD},
-#endif
+ {// 0: Automatic Browser Extension download. - Shouldn't prompt for
+ // browser
+ // extension downloads even if "Prompt for download" preference is
+ // set.
+ AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", extensions::Extension::kMimeType,
+ FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+
+ EXPECT_UNCONFIRMED},
+
+ {// 1: Automatic User Script - Shouldn't prompt for user script downloads
+ // even if "Prompt for download" preference is set.
+ AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.user.js", "",
+ FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.user.js"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+
+ EXPECT_CRDOWNLOAD},
};
SetPromptForDownload(true);
@@ -1264,7 +1477,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) {
// If the download path is managed, then we don't show any prompts.
// Note that if the download path is managed, then PromptForDownload() is false.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ManagedPath) {
+TEST_F(DownloadTargetDeterminerTest, ManagedPath) {
const DownloadTestCase kManagedPathTestCases[] = {
{// 0: Automatic Safe
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
@@ -1293,7 +1506,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ManagedPath) {
// Test basic functionality supporting extensions that want to override download
// filenames.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsSafe) {
+TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsSafe) {
const DownloadTestCase kNotifyExtensionsTestCases[] = {
{// 0: Automatic Safe
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
@@ -1305,7 +1518,6 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsSafe) {
EXPECT_CRDOWNLOAD},
-#if !BUILDFLAG(ANDROID_JAVA_UI)
{// 1: Save_As Safe
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
@@ -1315,14 +1527,13 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsSafe) {
DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_CRDOWNLOAD},
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
{// 2: Automatic Dangerous
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx",
- "", FILE_PATH_LITERAL(""),
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("overridden/foo.crx"),
+ FILE_PATH_LITERAL("overridden/foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
@@ -1346,16 +1557,16 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsSafe) {
// Test that filenames provided by extensions are passed into SafeBrowsing
// checks and dangerous download checks.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsUnsafe) {
+TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsUnsafe) {
const DownloadTestCase kNotHandledBySafeBrowsing = {
AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
DownloadFileType::ALLOW_ON_USER_GESTURE,
- "http://example.com/foo.crx.remove",
+ "http://example.com/foo.kindabad.remove",
"text/plain",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("overridden/foo.crx"),
+ FILE_PATH_LITERAL("overridden/foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED};
@@ -1364,11 +1575,11 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsUnsafe) {
AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
DownloadFileType::ALLOW_ON_USER_GESTURE,
- "http://example.com/foo.crx.remove",
+ "http://example.com/foo.kindabad.remove",
"text/plain",
FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("overridden/foo.crx"),
+ FILE_PATH_LITERAL("overridden/foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED};
@@ -1385,8 +1596,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsUnsafe) {
// Test that conflict actions set by extensions are passed correctly into
// ReserveVirtualPath.
-TEST_F(DownloadTargetDeterminerTest,
- TargetDeterminer_NotifyExtensionsConflict) {
+TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsConflict) {
const DownloadTestCase kNotifyExtensionsTestCase = {
AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
@@ -1401,8 +1611,8 @@ TEST_F(DownloadTargetDeterminerTest,
EXPECT_CRDOWNLOAD};
const DownloadTestCase& test_case = kNotifyExtensionsTestCase;
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(0, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(0, test_case);
base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt"));
base::FilePath full_overridden_path =
GetPathInDownloadDir(overridden_path.value());
@@ -1412,10 +1622,11 @@ TEST_F(DownloadTargetDeterminerTest,
.WillOnce(WithArg<2>(
ScheduleCallback2(overridden_path,
DownloadPathReservationTracker::OVERWRITE)));
- EXPECT_CALL(*delegate(), ReserveVirtualPath(
- _, full_overridden_path, true, DownloadPathReservationTracker::OVERWRITE,
- _)).WillOnce(WithArg<4>(
- ScheduleCallback2(full_overridden_path, true)));
+ EXPECT_CALL(*delegate(),
+ ReserveVirtualPath(_, full_overridden_path, true,
+ DownloadPathReservationTracker::OVERWRITE, _))
+ .WillOnce(WithArg<4>(ScheduleCallback2(full_overridden_path,
+ DownloadTargetResult::SUCCESS)));
RunTestCase(test_case, base::FilePath(), item.get());
@@ -1424,20 +1635,19 @@ TEST_F(DownloadTargetDeterminerTest,
.WillOnce(WithArg<2>(
ScheduleCallback2(overridden_path,
DownloadPathReservationTracker::PROMPT)));
- EXPECT_CALL(*delegate(), ReserveVirtualPath(
- _, full_overridden_path, true, DownloadPathReservationTracker::PROMPT, _))
- .WillOnce(WithArg<4>(
- ScheduleCallback2(full_overridden_path, true)));
+ EXPECT_CALL(*delegate(),
+ ReserveVirtualPath(_, full_overridden_path, true,
+ DownloadPathReservationTracker::PROMPT, _))
+ .WillOnce(WithArg<4>(ScheduleCallback2(full_overridden_path,
+ DownloadTargetResult::SUCCESS)));
RunTestCase(test_case, base::FilePath(), item.get());
}
-#if !BUILDFLAG(ANDROID_JAVA_UI)
// Test that relative paths returned by extensions are always relative to the
// default downloads path.
-TEST_F(DownloadTargetDeterminerTest,
- TargetDeterminer_NotifyExtensionsDefaultPath) {
+TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsDefaultPath) {
const DownloadTestCase kNotifyExtensionsTestCase = {
- SAVE_AS,
+ AUTOMATIC,
content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DownloadFileType::NOT_DANGEROUS,
"http://example.com/foo.txt",
@@ -1445,13 +1655,13 @@ TEST_F(DownloadTargetDeterminerTest,
FILE_PATH_LITERAL(""),
FILE_PATH_LITERAL("overridden/foo.txt"),
- DownloadItem::TARGET_DISPOSITION_PROMPT,
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_CRDOWNLOAD};
const DownloadTestCase& test_case = kNotifyExtensionsTestCase;
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(0, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(0, test_case);
base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt"));
base::FilePath full_overridden_path =
GetPathInDownloadDir(overridden_path.value());
@@ -1463,16 +1673,10 @@ TEST_F(DownloadTargetDeterminerTest,
.WillOnce(WithArg<2>(
ScheduleCallback2(overridden_path,
DownloadPathReservationTracker::UNIQUIFY)));
- EXPECT_CALL(*delegate(),
- PromptUserForDownloadPath(_, full_overridden_path, _))
- .WillOnce(WithArg<2>(
- ScheduleCallback(full_overridden_path)));
RunTestCase(test_case, base::FilePath(), item.get());
}
-#endif // !BUILDFLAG(ANDROID_JAVA_UI)
-TEST_F(DownloadTargetDeterminerTest,
- TargetDeterminer_InitialVirtualPathUnsafe) {
+TEST_F(DownloadTargetDeterminerTest, InitialVirtualPathUnsafe) {
const base::FilePath::CharType* kInitialPath =
FILE_PATH_LITERAL("some_path/bar.html");
@@ -1493,8 +1697,8 @@ TEST_F(DownloadTargetDeterminerTest,
EXPECT_CRDOWNLOAD};
const DownloadTestCase& test_case = kInitialPathTestCase;
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(1, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(1, test_case);
EXPECT_CALL(*item, GetLastReason())
.WillRepeatedly(Return(
content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED));
@@ -1508,7 +1712,7 @@ TEST_F(DownloadTargetDeterminerTest,
// the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be
// prompted, and not otherwise. These test cases shouldn't result in prompting
// since the error is set to NETWORK_FAILED.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
+TEST_F(DownloadTargetDeterminerTest, ResumedNoPrompt) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType* kInitialPath =
@@ -1518,8 +1722,8 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
{// 0: Automatic Safe: Initial path is ignored since the user has not been
// prompted before.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "text/plain",
- FILE_PATH_LITERAL(""),
+ DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
+ "text/plain", FILE_PATH_LITERAL(""),
FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
@@ -1527,8 +1731,8 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
{// 1: Save_As Safe: Initial path used.
SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "text/plain",
- FILE_PATH_LITERAL(""),
+ DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
+ "text/plain", FILE_PATH_LITERAL(""),
kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT,
@@ -1537,10 +1741,11 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
{// 2: Automatic Dangerous: Initial path is ignored since the user hasn't
// been prompted before.
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", "",
- FILE_PATH_LITERAL(""),
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE,
+ FILE_PATH_LITERAL("foo.kindabad"),
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
@@ -1555,16 +1760,16 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
EXPECT_LOCAL_PATH},
};
- // The test assumes that .crx files have a danger level of
+ // The test assumes that .kindabad files have a danger level of
// ALLOW_ON_USER_GESTURE.
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "Running test case " << i);
const DownloadTestCase& test_case = kResumedTestCases[i];
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_case);
base::FilePath expected_path =
GetPathInDownloadDir(test_case.expected_local_path);
ON_CALL(*item.get(), GetLastReason())
@@ -1576,7 +1781,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _))
.Times(test_case.test_type == AUTOMATIC ? 1 : 0);
EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _))
+ EXPECT_CALL(*delegate(), RequestConfirmation(_, expected_path, _, _))
.Times(0);
EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _));
@@ -1586,7 +1791,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) {
// Test that a forced download doesn't prompt, even if the interrupt reason
// suggests that the target path may not be suitable for downloads.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) {
+TEST_F(DownloadTargetDeterminerTest, ResumedForcedDownload) {
const base::FilePath::CharType* kInitialPath =
FILE_PATH_LITERAL("some_path/bar.txt");
const DownloadTestCase kResumedForcedDownload = {
@@ -1606,15 +1811,14 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) {
const DownloadTestCase& test_case = kResumedForcedDownload;
base::FilePath expected_path =
GetPathInDownloadDir(test_case.expected_local_path);
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(0, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(0, test_case);
ON_CALL(*item.get(), GetLastReason())
.WillByDefault(Return(content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE));
EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _))
.Times(test_case.test_type == AUTOMATIC ? 1 : 0);
EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _))
- .Times(0);
+ EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0);
EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _));
RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get());
@@ -1625,7 +1829,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) {
// the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be
// prompted, and not otherwise. These test cases result in prompting since the
// error is set to NO_SPACE.
-TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedWithPrompt) {
+TEST_F(DownloadTargetDeterminerTest, ResumedWithPrompt) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType* kInitialPath =
@@ -1637,12 +1841,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedWithPrompt) {
DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt",
"text/plain", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.txt"),
-#if BUILDFLAG(ANDROID_JAVA_UI)
- DownloadItem::TARGET_DISPOSITION_OVERWRITE,
-#else
- DownloadItem::TARGET_DISPOSITION_PROMPT,
-#endif
+ FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT,
EXPECT_CRDOWNLOAD},
{// 1: Save_As Safe
@@ -1656,53 +1855,33 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedWithPrompt) {
{
// 2: Automatic Dangerous
- AUTOMATIC,
-#if BUILDFLAG(ANDROID_JAVA_UI)
- // If we don't prompt user, the file will be treated as dangerous.
- content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE,
-#else
- content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
- DownloadFileType::NOT_DANGEROUS,
-#endif
- "http://example.com/foo.crx", "", FILE_PATH_LITERAL(""),
-
- FILE_PATH_LITERAL("foo.crx"),
-#if BUILDFLAG(ANDROID_JAVA_UI)
- DownloadItem::TARGET_DISPOSITION_OVERWRITE,
- // Dangerous download will have an unconfirmed intermediate file name.
- EXPECT_UNCONFIRMED,
-#else
+ AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
+ DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.kindabad",
svaldez 2016/10/28 17:29:36 Should this be ".bad"?
asanka 2016/11/07 19:50:15 Added another test case for .bad. The semantics ar
+ "", FILE_PATH_LITERAL(""),
+
+ FILE_PATH_LITERAL("foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_PROMPT, EXPECT_CRDOWNLOAD,
-#endif
},
};
- // The test assumes that .xml files have a danger level of
- // ALLOW_ON_USER_GESTURE.
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "Running test case " << i);
download_prefs()->SetSaveFilePath(test_download_dir());
const DownloadTestCase& test_case = kResumedTestCases[i];
base::FilePath expected_path =
GetPathInDownloadDir(test_case.expected_local_path);
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_case));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_case);
ON_CALL(*item.get(), GetLastReason())
.WillByDefault(Return(
content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE));
EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _))
.Times(test_case.test_type == AUTOMATIC ? 1 : 0);
EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
-#if BUILDFLAG(ANDROID_JAVA_UI)
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _))
- .Times(0);
-#else
- EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _));
-#endif
+ EXPECT_CALL(*delegate(), RequestConfirmation(_, expected_path, _, _));
EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _));
RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get());
@@ -1710,8 +1889,7 @@ TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedWithPrompt) {
}
// Test intermediate filename generation for resumed downloads.
-TEST_F(DownloadTargetDeterminerTest,
- TargetDeterminer_IntermediateNameForResumed) {
+TEST_F(DownloadTargetDeterminerTest, IntermediateNameForResumed) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType kInitialPath[] =
@@ -1754,10 +1932,10 @@ TEST_F(DownloadTargetDeterminerTest,
{{// 2: Automatic Dangerous
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx",
- "", FILE_PATH_LITERAL(""),
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"),
+ FILE_PATH_LITERAL("foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
@@ -1766,10 +1944,10 @@ TEST_F(DownloadTargetDeterminerTest,
{{// 3: Automatic Dangerous
AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE,
- DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx",
- "", FILE_PATH_LITERAL(""),
+ DownloadFileType::ALLOW_ON_USER_GESTURE,
+ "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""),
- FILE_PATH_LITERAL("foo.crx"),
+ FILE_PATH_LITERAL("foo.kindabad"),
DownloadItem::TARGET_DISPOSITION_OVERWRITE,
EXPECT_UNCONFIRMED},
@@ -1793,17 +1971,17 @@ TEST_F(DownloadTargetDeterminerTest,
FILE_PATH_LITERAL("forced-foo.txt")},
};
- // The test assumes that .crx files have a danger level of
+ // The test assumes that .kindabad files have a danger level of
// ALLOW_ON_USER_GESTURE.
ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE,
- Policies()->GetFileDangerLevel(
- base::FilePath(FILE_PATH_LITERAL("foo.crx"))));
+ safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
+ base::FilePath(FILE_PATH_LITERAL("foo.kindabad"))));
for (size_t i = 0; i < arraysize(kIntermediateNameTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "Running test case " << i);
const IntermediateNameTestCase& test_case = kIntermediateNameTestCases[i];
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_case.general));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_case.general);
ON_CALL(*item.get(), GetLastReason())
.WillByDefault(Return(
@@ -1826,8 +2004,7 @@ TEST_F(DownloadTargetDeterminerTest,
}
// Test MIME type determination based on the target filename.
-TEST_F(DownloadTargetDeterminerTest,
- TargetDeterminer_MIMETypeDetermination) {
+TEST_F(DownloadTargetDeterminerTest, MIMETypeDetermination) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType kInitialPath[] =
@@ -1900,7 +2077,6 @@ TEST_F(DownloadTargetDeterminerTest,
EXPECT_CRDOWNLOAD},
""},
-
};
ON_CALL(*delegate(), GetFileMimeType(
@@ -1911,8 +2087,8 @@ TEST_F(DownloadTargetDeterminerTest,
for (size_t i = 0; i < arraysize(kMIMETypeTestCases); ++i) {
SCOPED_TRACE(testing::Message() << "Running test case " << i);
const MIMETypeTestCase& test_case = kMIMETypeTestCases[i];
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(i, test_case.general));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(i, test_case.general);
std::unique_ptr<DownloadTargetInfo> target_info =
RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath),
item.get());
@@ -2033,8 +2209,7 @@ class DownloadTargetDeterminerTestWithPlugin
// Check if secure handling of filetypes is determined correctly for PPAPI
// plugins.
-TEST_F(DownloadTargetDeterminerTestWithPlugin,
- TargetDeterminer_CheckForSecureHandling_PPAPI) {
+TEST_F(DownloadTargetDeterminerTestWithPlugin, CheckForSecureHandling_PPAPI) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType kInitialPath[] =
@@ -2071,8 +2246,8 @@ TEST_F(DownloadTargetDeterminerTestWithPlugin,
GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _))
.WillByDefault(WithArg<1>(
ScheduleCallback(kTestMIMEType)));
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(1, kSecureHandlingTestCase));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(1, kSecureHandlingTestCase);
std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer(
GetPathInDownloadDir(kInitialPath), item.get());
EXPECT_FALSE(target_info->is_filetype_handled_safely);
@@ -2103,7 +2278,7 @@ TEST_F(DownloadTargetDeterminerTestWithPlugin,
// Check if secure handling of filetypes is determined correctly for
// BrowserPlugins.
TEST_F(DownloadTargetDeterminerTestWithPlugin,
- TargetDeterminer_CheckForSecureHandling_BrowserPlugin) {
+ CheckForSecureHandling_BrowserPlugin) {
// All test cases run with GetPathInDownloadDir(kInitialPath) as the inital
// path.
const base::FilePath::CharType kInitialPath[] =
@@ -2140,8 +2315,8 @@ TEST_F(DownloadTargetDeterminerTestWithPlugin,
GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _))
.WillByDefault(WithArg<1>(
ScheduleCallback(kTestMIMEType)));
- std::unique_ptr<content::MockDownloadItem> item(
- CreateActiveDownloadItem(1, kSecureHandlingTestCase));
+ std::unique_ptr<content::MockDownloadItem> item =
+ CreateActiveDownloadItem(1, kSecureHandlingTestCase);
std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer(
GetPathInDownloadDir(kInitialPath), item.get());
EXPECT_FALSE(target_info->is_filetype_handled_safely);

Powered by Google App Engine
This is Rietveld 408576698