diff options
author | noelutz@google.com <noelutz@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-17 22:47:40 +0000 |
---|---|---|
committer | noelutz@google.com <noelutz@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-17 22:47:40 +0000 |
commit | 3ab4c0af18aa95289f7d97da690e112a0cba8c77 (patch) | |
tree | 3caa5cf3362a7025254a95c01d57f288902dffdb /chrome/browser/download/download_manager_unittest.cc | |
parent | b5703e977ae3c4ee693e233fb0d2de6ccc87d4b5 (diff) | |
download | chromium_src-3ab4c0af18aa95289f7d97da690e112a0cba8c77.zip chromium_src-3ab4c0af18aa95289f7d97da690e112a0cba8c77.tar.gz chromium_src-3ab4c0af18aa95289f7d97da690e112a0cba8c77.tar.bz2 |
Propagate the SafeBrowsing download protection verdict to the DownloadItem.
This is where the UI will be notified when a malicious binary is being
downloaded. The UI currently does not support displaying a warning after
the download started. We'll fix that in a separate CL.
BUG=102540
TEST=No visible changes.
Review URL: http://codereview.chromium.org/8468020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_manager_unittest.cc')
-rw-r--r-- | chrome/browser/download/download_manager_unittest.cc | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/chrome/browser/download/download_manager_unittest.cc b/chrome/browser/download/download_manager_unittest.cc index b99a466..b794cd2 100644 --- a/chrome/browser/download/download_manager_unittest.cc +++ b/chrome/browser/download/download_manager_unittest.cc @@ -143,17 +143,6 @@ class DownloadManagerTest : public testing::Test { return file_manager_; } - // Make sure download item |id| was set with correct safety state for - // given |is_dangerous_file| and |is_dangerous_url|. - bool VerifySafetyState(bool is_dangerous_file, - bool is_dangerous_url, - int id) { - DownloadItem::SafetyState safety_state = - download_manager_->GetDownloadItem(id)->safety_state(); - return (is_dangerous_file || is_dangerous_url) ? - safety_state != DownloadItem::SAFE : safety_state == DownloadItem::SAFE; - } - DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); }; @@ -262,29 +251,29 @@ const struct { const struct { FilePath::StringType suggested_path; - bool is_dangerous_file; - bool is_dangerous_url; + DownloadStateInfo::DangerType danger; bool finish_before_rename; int expected_rename_count; } kDownloadRenameCases[] = { // Safe download, download finishes BEFORE file name determined. // Renamed twice (linear path through UI). Crdownload file does not need // to be deleted. - { FILE_PATH_LITERAL("foo.zip"), false, false, true, 2, }, - // Dangerous download (file is dangerous or download URL is not safe or both), - // download finishes BEFORE file name determined. Needs to be renamed only - // once. - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, false, true, 1, }, - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), false, true, true, 1, }, - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, true, true, 1, }, + { FILE_PATH_LITERAL("foo.zip"), DownloadStateInfo::NOT_DANGEROUS, true, 2, }, + // Potentially dangerous download (e.g., file is dangerous), download finishes + // BEFORE file name determined. Needs to be renamed only once. + { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), + DownloadStateInfo::MAYBE_DANGEROUS_CONTENT, true, 1, }, + { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), + DownloadStateInfo::DANGEROUS_FILE, true, 1, }, // Safe download, download finishes AFTER file name determined. // Needs to be renamed twice. - { FILE_PATH_LITERAL("foo.zip"), false, false, false, 2, }, - // Dangerous download, download finishes AFTER file name determined. - // Needs to be renamed only once. - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, false, false, 1, }, - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), false, true, false, 1, }, - { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), true, true, false, 1, }, + { FILE_PATH_LITERAL("foo.zip"), DownloadStateInfo::NOT_DANGEROUS, false, 2, }, + // Potentially dangerous download, download finishes AFTER file name + // determined. Needs to be renamed only once. + { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), + DownloadStateInfo::MAYBE_DANGEROUS_CONTENT, false, 1, }, + { FILE_PATH_LITERAL("Unconfirmed xxx.crdownload"), + DownloadStateInfo::DANGEROUS_FILE, false, 1, }, }; // This is an observer that records what download IDs have opened a select @@ -435,10 +424,9 @@ TEST_F(DownloadManagerTest, DownloadRenameTest) { download_manager_->CreateDownloadItem(info.get(), DownloadRequestHandle()); DownloadItem* download = GetActiveDownloadItem(i); ASSERT_TRUE(download != NULL); - if (kDownloadRenameCases[i].is_dangerous_file) - download->MarkFileDangerous(); - if (kDownloadRenameCases[i].is_dangerous_url) - download->MarkUrlDangerous(); + DownloadStateInfo state = download->state_info(); + state.danger = kDownloadRenameCases[i].danger; + download->SetFileCheckResults(state); int32* id_ptr = new int32; *id_ptr = i; // Deleted in FileSelected(). @@ -451,14 +439,10 @@ TEST_F(DownloadManagerTest, DownloadRenameTest) { message_loop_.RunAllPending(); OnResponseCompleted(i, 1024, std::string("fake_hash")); } - message_loop_.RunAllPending(); EXPECT_EQ( kDownloadRenameCases[i].expected_rename_count, recorder.Count(MockDownloadFile::StatisticsRecorder::STAT_RENAME)); - EXPECT_TRUE(VerifySafetyState(kDownloadRenameCases[i].is_dangerous_file, - kDownloadRenameCases[i].is_dangerous_url, - i)); } } |