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

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

Issue 2439533002: Download Feedback Service should upload all eligible downloads (Closed)
Patch Set: make windows 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 2ae0ef0dd8ac7ed673a033871921fbe26f7aecaf..23002f0af4eb8a42101fef555b3ef300e016d10e 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -1539,7 +1539,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);
@@ -1551,7 +1551,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)));
@@ -1559,6 +1561,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();
@@ -1575,10 +1597,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);
}
@@ -1596,10 +1619,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());
}
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698