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

Side by Side Diff: chrome/browser/ui/webui/settings/downloads_handler_unittest.cc

Issue 2711823002: MD Settings: Add "Auto Open" setting to Downloads C++ handler. (Closed)
Patch Set: fix teardown Created 3 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/settings/downloads_handler.h"
6
7 #include "chrome/browser/download/chrome_download_manager_delegate.h"
8 #include "chrome/browser/download/download_prefs.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "components/prefs/pref_service.h"
12 #include "content/public/browser/web_ui.h"
13 #include "content/public/test/mock_download_manager.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/public/test/test_web_ui.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace settings {
19
20 class DownloadsHandlerTest : public testing::Test {
21 public:
22 DownloadsHandlerTest()
23 : download_manager_(new content::MockDownloadManager()),
24 chrome_download_manager_delegate_(&profile_),
25 handler_(&profile_) {
26 content::BrowserContext::SetDownloadManagerForTesting(&profile_,
27 download_manager_);
28 EXPECT_EQ(download_manager_,
29 content::BrowserContext::GetDownloadManager(&profile_));
30
31 EXPECT_CALL(*download_manager_, GetDelegate())
32 .WillRepeatedly(testing::Return(&chrome_download_manager_delegate_));
33 EXPECT_CALL(*download_manager_, Shutdown());
34
35 handler_.set_web_ui(&test_web_ui_);
36 }
37
38 void SetUp() override {
39 EXPECT_TRUE(test_web_ui_.call_data().empty());
40
41 base::ListValue args;
42 handler()->HandleInitialize(&args);
43
44 EXPECT_TRUE(handler()->IsJavascriptAllowed());
45 VerifyAutoOpenDownloadsChangedCallback();
46
47 test_web_ui_.ClearTrackedCalls();
48 }
49
50 void TearDown() override {
51 chrome_download_manager_delegate_.Shutdown();
52 testing::Test::TearDown();
53 }
54
55 void VerifyAutoOpenDownloadsChangedCallback() {
56 EXPECT_EQ(1u, test_web_ui_.call_data().size());
57
58 auto& data = *(test_web_ui_.call_data().back());
59 EXPECT_EQ("cr.webUIListenerCallback", data.function_name());
60 std::string event;
61 ASSERT_TRUE(data.arg1()->GetAsString(&event));
62 EXPECT_EQ("auto-open-downloads-changed", event);
63 bool auto_open_downloads = false;
64 ASSERT_TRUE(data.arg2()->GetAsBoolean(&auto_open_downloads));
65 EXPECT_FALSE(auto_open_downloads);
66 }
67
68 Profile* profile() { return &profile_; }
69 DownloadsHandler* handler() { return &handler_; }
70
71 private:
72 content::TestBrowserThreadBundle thread_bundle_;
73 content::TestWebUI test_web_ui_;
74 TestingProfile profile_;
75
76 // This is heap allocated because its ownership is transferred to |profile_|.
77 content::MockDownloadManager* download_manager_;
78 ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
79
80 DownloadsHandler handler_;
81 };
82
83 TEST_F(DownloadsHandlerTest, AutoOpenDownloads) {
84 // Touch the pref.
85 profile()->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, "");
86 VerifyAutoOpenDownloadsChangedCallback();
87 }
88
89 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/downloads_handler.cc ('k') | chrome/browser/ui/webui/settings/md_settings_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698