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

Side by Side 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, 5 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h" 5 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h"
6 6
7 #include <vector>
8
9 #include "chrome/browser/download/download_item_model.h"
7 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "content/public/test/mock_download_item.h"
8 #include "content/public/test/mock_download_manager.h" 12 #include "content/public/test/mock_download_manager.h"
9 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "content/public/test/test_web_ui.h" 14 #include "content/public/test/test_web_ui.h"
11 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
13 17
14 namespace { 18 namespace {
15 19
16 class TestMdDownloadsDOMHandler : public MdDownloadsDOMHandler { 20 class TestMdDownloadsDOMHandler : public MdDownloadsDOMHandler {
17 public: 21 public:
18 explicit TestMdDownloadsDOMHandler(content::DownloadManager* download_manager, 22 explicit TestMdDownloadsDOMHandler(content::DownloadManager* download_manager,
19 content::WebUI* web_ui) 23 content::WebUI* web_ui)
20 : MdDownloadsDOMHandler(download_manager, web_ui) {} 24 : MdDownloadsDOMHandler(download_manager, web_ui) {}
21 25
22 using MdDownloadsDOMHandler::set_web_ui; 26 using MdDownloadsDOMHandler::set_web_ui;
27 using MdDownloadsDOMHandler::FinalizeRemovals;
28 using MdDownloadsDOMHandler::RemoveDownloads;
23 }; 29 };
24 30
25 } // namespace 31 } // namespace
26 32
27 // A fixture to test MdDownloadsDOMHandler. 33 // A fixture to test MdDownloadsDOMHandler.
28 class MdDownloadsDOMHandlerTest : public testing::Test { 34 class MdDownloadsDOMHandlerTest : public testing::Test {
29 public: 35 public:
30 // testing::Test: 36 // testing::Test:
31 void SetUp() override { 37 void SetUp() override {
32 ON_CALL(manager_, GetBrowserContext()) 38 ON_CALL(manager_, GetBrowserContext())
(...skipping 27 matching lines...) Expand all
60 TestMdDownloadsDOMHandler handler(manager(), web_ui()); 66 TestMdDownloadsDOMHandler handler(manager(), web_ui());
61 handler.set_web_ui(web_ui()); 67 handler.set_web_ui(web_ui());
62 68
63 base::ListValue empty_search_terms; 69 base::ListValue empty_search_terms;
64 handler.HandleGetDownloads(&empty_search_terms); 70 handler.HandleGetDownloads(&empty_search_terms);
65 71
66 EXPECT_EQ(1U, web_ui()->call_data().size()); 72 EXPECT_EQ(1U, web_ui()->call_data().size());
67 EXPECT_EQ("downloads.Manager.insertItems", 73 EXPECT_EQ("downloads.Manager.insertItems",
68 web_ui()->call_data()[0]->function_name()); 74 web_ui()->call_data()[0]->function_name());
69 } 75 }
76
77 TEST_F(MdDownloadsDOMHandlerTest, ClearAll) {
78 std::vector<content::DownloadItem*> downloads;
79
80 // Safe, in-progress items should be passed over.
81 testing::StrictMock<content::MockDownloadItem> in_progress;
82 EXPECT_CALL(in_progress, IsDangerous()).WillOnce(testing::Return(false));
83 EXPECT_CALL(in_progress, GetState()).WillOnce(
84 testing::Return(content::DownloadItem::IN_PROGRESS));
85 downloads.push_back(&in_progress);
86
87 // Dangerous items should be removed (regardless of state).
88 testing::StrictMock<content::MockDownloadItem> dangerous;
89 EXPECT_CALL(dangerous, IsDangerous()).WillOnce(testing::Return(true));
90 EXPECT_CALL(dangerous, Remove());
91 downloads.push_back(&dangerous);
92
93 // Completed items should be marked as hidden from the shelf.
94 testing::StrictMock<content::MockDownloadItem> completed;
95 EXPECT_CALL(completed, IsDangerous()).WillOnce(testing::Return(false));
96 EXPECT_CALL(completed, GetState()).WillOnce(
97 testing::Return(content::DownloadItem::COMPLETE));
98 EXPECT_CALL(completed, GetId()).WillOnce(testing::Return(1));
99 EXPECT_CALL(completed, UpdateObservers());
100 downloads.push_back(&completed);
101
102 ASSERT_TRUE(DownloadItemModel(&completed).ShouldShowInShelf());
103
104 TestMdDownloadsDOMHandler handler(manager(), web_ui());
105 handler.RemoveDownloads(downloads);
106
107 // Ensure |completed| has been "soft removed" (i.e. can be revived).
108 EXPECT_FALSE(DownloadItemModel(&completed).ShouldShowInShelf());
109
110 // Make sure |completed| actually get removed when removals are "finalized".
111 EXPECT_CALL(*manager(), GetDownload(1)).WillOnce(testing::Return(&completed));
112 EXPECT_CALL(completed, Remove());
113 handler.FinalizeRemovals();
114 }
OLDNEW
« 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