| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/settings/downloads_handler.h" | 5 #include "chrome/browser/ui/webui/settings/downloads_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 8 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 9 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 11 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 12 #include "content/public/browser/web_ui.h" | 13 #include "content/public/browser/web_ui.h" |
| 13 #include "content/public/test/mock_download_manager.h" | 14 #include "content/public/test/mock_download_manager.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "content/public/test/test_web_ui.h" | 16 #include "content/public/test/test_web_ui.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace settings { | 19 namespace settings { |
| 19 | 20 |
| 20 class DownloadsHandlerTest : public testing::Test { | 21 class DownloadsHandlerTest : public testing::Test { |
| 21 public: | 22 public: |
| 22 DownloadsHandlerTest() | 23 DownloadsHandlerTest() |
| 23 : download_manager_(new content::MockDownloadManager()), | 24 : download_manager_(new content::MockDownloadManager()), |
| 24 chrome_download_manager_delegate_(&profile_), | 25 chrome_download_manager_delegate_(&profile_), |
| 25 handler_(&profile_) { | 26 handler_(&profile_) { |
| 26 content::BrowserContext::SetDownloadManagerForTesting(&profile_, | 27 content::BrowserContext::SetDownloadManagerForTesting( |
| 27 download_manager_); | 28 &profile_, base::WrapUnique(download_manager_)); |
| 28 EXPECT_EQ(download_manager_, | 29 EXPECT_EQ(download_manager_, |
| 29 content::BrowserContext::GetDownloadManager(&profile_)); | 30 content::BrowserContext::GetDownloadManager(&profile_)); |
| 30 | 31 |
| 31 EXPECT_CALL(*download_manager_, GetDelegate()) | 32 EXPECT_CALL(*download_manager_, GetDelegate()) |
| 32 .WillRepeatedly(testing::Return(&chrome_download_manager_delegate_)); | 33 .WillRepeatedly(testing::Return(&chrome_download_manager_delegate_)); |
| 33 EXPECT_CALL(*download_manager_, Shutdown()); | 34 EXPECT_CALL(*download_manager_, Shutdown()); |
| 34 | 35 |
| 35 handler_.set_web_ui(&test_web_ui_); | 36 handler_.set_web_ui(&test_web_ui_); |
| 36 } | 37 } |
| 37 | 38 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 } | 67 } |
| 67 | 68 |
| 68 Profile* profile() { return &profile_; } | 69 Profile* profile() { return &profile_; } |
| 69 DownloadsHandler* handler() { return &handler_; } | 70 DownloadsHandler* handler() { return &handler_; } |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 content::TestBrowserThreadBundle thread_bundle_; | 73 content::TestBrowserThreadBundle thread_bundle_; |
| 73 content::TestWebUI test_web_ui_; | 74 content::TestWebUI test_web_ui_; |
| 74 TestingProfile profile_; | 75 TestingProfile profile_; |
| 75 | 76 |
| 76 // This is heap allocated because its ownership is transferred to |profile_|. | 77 content::MockDownloadManager* download_manager_; // Owned by |profile_|. |
| 77 content::MockDownloadManager* download_manager_; | |
| 78 ChromeDownloadManagerDelegate chrome_download_manager_delegate_; | 78 ChromeDownloadManagerDelegate chrome_download_manager_delegate_; |
| 79 | 79 |
| 80 DownloadsHandler handler_; | 80 DownloadsHandler handler_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 TEST_F(DownloadsHandlerTest, AutoOpenDownloads) { | 83 TEST_F(DownloadsHandlerTest, AutoOpenDownloads) { |
| 84 // Touch the pref. | 84 // Touch the pref. |
| 85 profile()->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, ""); | 85 profile()->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, ""); |
| 86 VerifyAutoOpenDownloadsChangedCallback(); | 86 VerifyAutoOpenDownloadsChangedCallback(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace settings | 89 } // namespace settings |
| OLD | NEW |