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

Unified Diff: content/browser/download/download_item_impl_unittest.cc

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: make try bots happy Created 4 years, 1 month 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: content/browser/download/download_item_impl_unittest.cc
diff --git a/content/browser/download/download_item_impl_unittest.cc b/content/browser/download/download_item_impl_unittest.cc
index 4f84f66dfe6a49dddbb3aa677460d08ceb629da6..7f047e66ca4f58623202537c157d181a961f5958 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -1541,7 +1541,7 @@ TEST_F(DownloadItemTest, CompleteDelegate_BlockTwice) {
EXPECT_EQ(DownloadItem::COMPLETE, item->GetState());
}
-TEST_F(DownloadItemTest, StealDangerousDownload) {
+TEST_F(DownloadItemTest, StealDangerousDownloadAndDiscard) {
DownloadItemImpl* item = CreateDownloadItem();
MockDownloadFile* download_file =
DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
@@ -1553,7 +1553,9 @@ TEST_F(DownloadItemTest, StealDangerousDownload) {
EXPECT_CALL(*download_file, Detach());
EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
+ item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
item->StealDangerousDownload(
+ true, // delete_file_after_feedback
base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
weak_ptr_factory.GetWeakPtr(),
base::Unretained(&returned_path)));
@@ -1561,6 +1563,26 @@ TEST_F(DownloadItemTest, StealDangerousDownload) {
EXPECT_EQ(full_path, returned_path);
}
+TEST_F(DownloadItemTest, StealDangerousDownloadAndKeep) {
+ DownloadItemImpl* item = CreateDownloadItem();
+ MockDownloadFile* download_file =
+ DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
+ ASSERT_TRUE(item->IsDangerous());
+ base::FilePath full_path(FILE_PATH_LITERAL("foo.txt"));
+ base::FilePath returned_path;
+ EXPECT_CALL(*download_file, FullPath()).WillOnce(ReturnRefOfCopy(full_path));
+ base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
+ item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
+ item->StealDangerousDownload(
+ false, // delete_file_after_feedback
+ base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
+ weak_ptr_factory.GetWeakPtr(),
+ base::Unretained(&returned_path)));
+ RunAllPendingInMessageLoops();
+ EXPECT_NE(full_path, returned_path);
+ CleanupItem(item, download_file, DownloadItem::IN_PROGRESS);
+}
+
TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) {
base::FilePath returned_path;
DownloadItemImpl* item = CreateDownloadItem();
@@ -1577,10 +1599,11 @@ TEST_F(DownloadItemTest, StealInterruptedDangerousDownload) {
EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
+ item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
item->StealDangerousDownload(
- base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
- weak_ptr_factory.GetWeakPtr(),
- base::Unretained(&returned_path)));
+ true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
+ weak_ptr_factory.GetWeakPtr(),
+ base::Unretained(&returned_path)));
RunAllPendingInMessageLoops();
EXPECT_EQ(full_path, returned_path);
}
@@ -1598,10 +1621,11 @@ TEST_F(DownloadItemTest, StealInterruptedNonResumableDangerousDownload) {
EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this);
+ item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>());
item->StealDangerousDownload(
- base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
- weak_ptr_factory.GetWeakPtr(),
- base::Unretained(&returned_path)));
+ true, base::Bind(&DownloadItemTest::OnDownloadFileAcquired,
+ weak_ptr_factory.GetWeakPtr(),
+ base::Unretained(&returned_path)));
RunAllPendingInMessageLoops();
EXPECT_TRUE(returned_path.empty());
}

Powered by Google App Engine
This is Rietveld 408576698