Chromium Code Reviews| 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()); |
|
Dan Beam
2016/05/03 04:11:38
why do you need to call set_web_ui here?
tommycli
2016/05/03 16:26:05
We must call it here because the web_ui passed in
|
| + |
| + 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()); |
| +} |