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

Unified Diff: chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc

Issue 2100443003: MD Downloads: "Clear All" should remove dangerous downloads for good (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc
diff --git a/chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc b/chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc
index de44c3832ff9f42ed28640a151fe4163bc468e8e..3310c8709b5d6e0e683f74659ea4384e30e66afa 100644
--- a/chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc
+++ b/chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler_unittest.cc
@@ -4,7 +4,11 @@
#include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h"
+#include <vector>
+
+#include "chrome/browser/download/download_item_model.h"
#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/mock_download_item.h"
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_web_ui.h"
@@ -20,6 +24,8 @@ class TestMdDownloadsDOMHandler : public MdDownloadsDOMHandler {
: MdDownloadsDOMHandler(download_manager, web_ui) {}
using MdDownloadsDOMHandler::set_web_ui;
+ using MdDownloadsDOMHandler::FinalizeRemovals;
+ using MdDownloadsDOMHandler::RemoveDownloads;
};
} // namespace
@@ -67,3 +73,42 @@ TEST_F(MdDownloadsDOMHandlerTest, HandleGetDownloads) {
EXPECT_EQ("downloads.Manager.insertItems",
web_ui()->call_data()[0]->function_name());
}
+
+TEST_F(MdDownloadsDOMHandlerTest, ClearAll) {
+ std::vector<content::DownloadItem*> downloads;
+
+ // Safe, in-progress items should be passed over.
+ testing::StrictMock<content::MockDownloadItem> in_progress;
+ EXPECT_CALL(in_progress, IsDangerous()).WillOnce(testing::Return(false));
+ EXPECT_CALL(in_progress, GetState()).WillOnce(
+ testing::Return(content::DownloadItem::IN_PROGRESS));
+ downloads.push_back(&in_progress);
+
+ // Dangerous items should be removed (regardless of state).
+ testing::StrictMock<content::MockDownloadItem> dangerous;
+ EXPECT_CALL(dangerous, IsDangerous()).WillOnce(testing::Return(true));
+ EXPECT_CALL(dangerous, Remove());
+ downloads.push_back(&dangerous);
+
+ // Completed items should be marked as hidden from the shelf.
+ testing::StrictMock<content::MockDownloadItem> completed;
+ EXPECT_CALL(completed, IsDangerous()).WillOnce(testing::Return(false));
+ EXPECT_CALL(completed, GetState()).WillOnce(
+ testing::Return(content::DownloadItem::COMPLETE));
+ EXPECT_CALL(completed, GetId()).WillOnce(testing::Return(1));
+ EXPECT_CALL(completed, UpdateObservers());
+ downloads.push_back(&completed);
+
+ ASSERT_TRUE(DownloadItemModel(&completed).ShouldShowInShelf());
+
+ TestMdDownloadsDOMHandler handler(manager(), web_ui());
+ handler.RemoveDownloads(downloads);
+
+ // Ensure |completed| has been "soft removed" (i.e. can be revived).
+ EXPECT_FALSE(DownloadItemModel(&completed).ShouldShowInShelf());
+
+ // Make sure |completed| actually get removed when removals are "finalized".
+ EXPECT_CALL(*manager(), GetDownload(1)).WillOnce(testing::Return(&completed));
+ EXPECT_CALL(completed, Remove());
+ handler.FinalizeRemovals();
+}
« no previous file with comments | « chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698