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

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

Issue 1938983003: WebUI: Update Downloads to fix bug introduced by JS lifecycle controls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 54f77a824a65d3d7dc4758aba9577f43bfb0c956..de44c3832ff9f42ed28640a151fe4163bc468e8e 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
@@ -11,21 +11,59 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-TEST(MdDownloadsDOMHandlerTest, ChecksForRemovedFiles) {
- content::TestBrowserThreadBundle thread_bundle;
- TestingProfile profile;
+namespace {
- testing::NiceMock<content::MockDownloadManager> manager;
- ON_CALL(manager, GetBrowserContext()).WillByDefault(
- testing::Return(&profile));
+class TestMdDownloadsDOMHandler : public MdDownloadsDOMHandler {
+ public:
+ explicit TestMdDownloadsDOMHandler(content::DownloadManager* download_manager,
+ content::WebUI* web_ui)
+ : MdDownloadsDOMHandler(download_manager, web_ui) {}
- content::TestWebUI web_ui;
+ using MdDownloadsDOMHandler::set_web_ui;
+};
- EXPECT_CALL(manager, CheckForHistoryFilesRemoval());
- MdDownloadsDOMHandler handler(&manager, &web_ui);
+} // namespace
- testing::Mock::VerifyAndClear(&manager);
+// A fixture to test MdDownloadsDOMHandler.
+class MdDownloadsDOMHandlerTest : public testing::Test {
+ public:
+ // testing::Test:
+ void SetUp() override {
+ ON_CALL(manager_, GetBrowserContext())
+ .WillByDefault(testing::Return(&profile_));
+ }
- EXPECT_CALL(manager, CheckForHistoryFilesRemoval());
+ TestingProfile* profile() { return &profile_; }
+ content::MockDownloadManager* manager() { return &manager_; }
+ content::TestWebUI* web_ui() { return &web_ui_; }
+
+ private:
+ // NOTE: The initialization order of these members matters.
+ content::TestBrowserThreadBundle thread_bundle_;
+ TestingProfile profile_;
+
+ testing::NiceMock<content::MockDownloadManager> manager_;
+ content::TestWebUI web_ui_;
+};
+
+TEST_F(MdDownloadsDOMHandlerTest, ChecksForRemovedFiles) {
+ EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval());
+ TestMdDownloadsDOMHandler handler(manager(), web_ui());
+
+ testing::Mock::VerifyAndClear(manager());
+
+ EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval());
handler.OnJavascriptDisallowed();
}
+
+TEST_F(MdDownloadsDOMHandlerTest, HandleGetDownloads) {
+ TestMdDownloadsDOMHandler handler(manager(), web_ui());
+ handler.set_web_ui(web_ui());
+
+ base::ListValue empty_search_terms;
+ handler.HandleGetDownloads(&empty_search_terms);
+
+ EXPECT_EQ(1U, web_ui()->call_data().size());
+ EXPECT_EQ("downloads.Manager.insertItems",
+ web_ui()->call_data()[0]->function_name());
+}
« 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