Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
| 8 #include "content/public/test/mock_download_manager.h" | 8 #include "content/public/test/mock_download_manager.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "content/public/test/test_web_ui.h" | 10 #include "content/public/test/test_web_ui.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 TEST(MdDownloadsDOMHandlerTest, ChecksForRemovedFiles) { | 14 namespace { |
| 15 content::TestBrowserThreadBundle thread_bundle; | |
| 16 TestingProfile profile; | |
| 17 | 15 |
| 18 testing::NiceMock<content::MockDownloadManager> manager; | 16 class TestMdDownloadsDOMHandler : public MdDownloadsDOMHandler { |
| 19 ON_CALL(manager, GetBrowserContext()).WillByDefault( | 17 public: |
| 20 testing::Return(&profile)); | 18 explicit TestMdDownloadsDOMHandler(content::DownloadManager* download_manager, |
| 19 content::WebUI* web_ui) | |
| 20 : MdDownloadsDOMHandler(download_manager, web_ui) {} | |
| 21 | 21 |
| 22 content::TestWebUI web_ui; | 22 using MdDownloadsDOMHandler::set_web_ui; |
| 23 }; | |
| 23 | 24 |
| 24 EXPECT_CALL(manager, CheckForHistoryFilesRemoval()); | 25 } // namespace |
| 25 MdDownloadsDOMHandler handler(&manager, &web_ui); | |
| 26 | 26 |
| 27 testing::Mock::VerifyAndClear(&manager); | 27 // A fixture to test MdDownloadsDOMHandler. |
| 28 class MdDownloadsDOMHandlerTest : public testing::Test { | |
| 29 public: | |
| 30 // testing::Test: | |
| 31 void SetUp() override { | |
| 32 ON_CALL(manager_, GetBrowserContext()) | |
| 33 .WillByDefault(testing::Return(&profile_)); | |
| 34 } | |
| 28 | 35 |
| 29 EXPECT_CALL(manager, CheckForHistoryFilesRemoval()); | 36 TestingProfile* profile() { return &profile_; } |
| 37 content::MockDownloadManager* manager() { return &manager_; } | |
| 38 content::TestWebUI* web_ui() { return &web_ui_; } | |
| 39 | |
| 40 private: | |
| 41 // NOTE: The initialization order of these members matters. | |
| 42 content::TestBrowserThreadBundle thread_bundle_; | |
| 43 TestingProfile profile_; | |
| 44 | |
| 45 testing::NiceMock<content::MockDownloadManager> manager_; | |
| 46 content::TestWebUI web_ui_; | |
| 47 }; | |
| 48 | |
| 49 TEST_F(MdDownloadsDOMHandlerTest, ChecksForRemovedFiles) { | |
| 50 EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval()); | |
| 51 TestMdDownloadsDOMHandler handler(manager(), web_ui()); | |
| 52 | |
| 53 testing::Mock::VerifyAndClear(manager()); | |
| 54 | |
| 55 EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval()); | |
| 30 handler.OnJavascriptDisallowed(); | 56 handler.OnJavascriptDisallowed(); |
| 31 } | 57 } |
| 58 | |
| 59 TEST_F(MdDownloadsDOMHandlerTest, HandleGetDownloads) { | |
| 60 TestMdDownloadsDOMHandler handler(manager(), web_ui()); | |
| 61 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
| |
| 62 | |
| 63 base::ListValue empty_search_terms; | |
| 64 handler.HandleGetDownloads(&empty_search_terms); | |
| 65 | |
| 66 EXPECT_EQ(1U, web_ui()->call_data().size()); | |
| 67 EXPECT_EQ("downloads.Manager.insertItems", | |
| 68 web_ui()->call_data()[0]->function_name()); | |
| 69 } | |
| OLD | NEW |