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

Side by Side Diff: chrome/browser/ui/views/settings_reset_prompt_dialog_browsertest.cc

Issue 2701313002: Adds a modal dialog implementation of the settings reset prompt. (Closed)
Patch Set: Fix constness in mock test class 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
« no previous file with comments | « chrome/browser/ui/views/settings_reset_prompt_dialog.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <initializer_list>
6 #include <map>
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/memory/ptr_util.h"
13 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
14 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom pt_controller.h"
17 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom pt_model.h"
18 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom pt_test_utils.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/test/test_browser_dialog.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h"
24
25 namespace {
26
27 using safe_browsing::MockProfileResetter;
28 using safe_browsing::MockSettingsResetPromptConfig;
29 using testing::_;
30 using testing::ElementsAre;
31 using testing::NiceMock;
32 using testing::Not;
33 using testing::Return;
34 using testing::ReturnRef;
35
36 constexpr char kHomepageUrl[] = "http://www.a-homepage.com/some/path";
37 constexpr char kSearchUrl[] = "http://www.a-search.com/some/path/?q={%s}";
38 constexpr char kStartupUrl1[] = "http://www.a-startup-1.com/some/path";
39 constexpr char kStartupUrl2[] = "http://www.a-startup-2.com/some/other/path";
40 constexpr char kExtensionId1[] = "abcdefghijklmnopabcdefghijklmnop";
41 constexpr char kExtensionId2[] = "bbcdefghijklmnopabcdefghijklmnop";
42 constexpr char kExtensionName1[] = "Extensions1";
43 constexpr char kExtensionName2[] = "Extensions2";
44
45 enum class SettingType {
46 DEFAULT_SEARCH_ENGINE,
47 STARTUP_PAGE,
48 HOMEPAGE,
49 EXTENSIONS, // Also disable some extensions.
50 };
51
52 class MockSettingsResetPromptModel
53 : public safe_browsing::SettingsResetPromptModel {
54 public:
55 // Create a mock model that pretends that the settings passed in via
56 // |settings_to_reset| require resetting. |settings_to_reset| must not be
57 // empty or have |EXTENSIONS| as the only member.
58 explicit MockSettingsResetPromptModel(Profile* profile,
59 std::set<SettingType> settings_to_reset)
60 : SettingsResetPromptModel(
61 profile,
62 base::MakeUnique<NiceMock<MockSettingsResetPromptConfig>>(),
63 base::MakeUnique<ResettableSettingsSnapshot>(profile),
64 base::MakeUnique<BrandcodedDefaultSettings>(),
65 base::MakeUnique<NiceMock<MockProfileResetter>>(profile)) {
66 EXPECT_FALSE(settings_to_reset.empty());
67 EXPECT_THAT(settings_to_reset, Not(ElementsAre(SettingType::EXTENSIONS)));
68
69 // Set up startup URLs and extensions to be returned by member functions
70 // based on which settings should require reset.
71 startup_urls_.push_back(GURL(kStartupUrl1));
72 startup_urls_.push_back(GURL(kStartupUrl2));
73 if (settings_to_reset.find(SettingType::STARTUP_PAGE) !=
74 settings_to_reset.end())
75 startup_urls_to_reset_ = startup_urls_;
76
77 if (settings_to_reset.find(SettingType::EXTENSIONS) !=
78 settings_to_reset.end()) {
79 extensions_ = {{kExtensionId1, safe_browsing::ExtensionInfo(
80 kExtensionId1, kExtensionName1)},
81 {kExtensionId2, safe_browsing::ExtensionInfo(
82 kExtensionId2, kExtensionName2)}};
83 }
84
85 ON_CALL(*this, PerformReset(_)).WillByDefault(Return());
86
87 ON_CALL(*this, ShouldPromptForReset())
88 .WillByDefault(Return(!settings_to_reset.empty()));
89
90 ON_CALL(*this, homepage()).WillByDefault(Return(GURL(kHomepageUrl)));
91 ON_CALL(*this, homepage_reset_state())
92 .WillByDefault(
93 Return(ChooseResetState(settings_to_reset, SettingType::HOMEPAGE)));
94
95 ON_CALL(*this, default_search()).WillByDefault(Return(GURL(kSearchUrl)));
96 ON_CALL(*this, default_search_reset_state())
97 .WillByDefault(Return(ChooseResetState(
98 settings_to_reset, SettingType::DEFAULT_SEARCH_ENGINE)));
99
100 ON_CALL(*this, startup_urls()).WillByDefault(ReturnRef(startup_urls_));
101 ON_CALL(*this, startup_urls_to_reset())
102 .WillByDefault(ReturnRef(startup_urls_to_reset_));
103 ON_CALL(*this, startup_urls_reset_state())
104 .WillByDefault(Return(
105 ChooseResetState(settings_to_reset, SettingType::STARTUP_PAGE)));
106
107 ON_CALL(*this, extensions_to_disable())
108 .WillByDefault(ReturnRef(extensions_));
109 }
110 ~MockSettingsResetPromptModel() override {}
111
112 MOCK_METHOD1(PerformReset, void(const base::Closure&));
113 MOCK_CONST_METHOD0(ShouldPromptForReset, bool());
114 MOCK_CONST_METHOD0(homepage, GURL());
115 MOCK_CONST_METHOD0(homepage_reset_state, ResetState());
116 MOCK_CONST_METHOD0(default_search, GURL());
117 MOCK_CONST_METHOD0(default_search_reset_state, ResetState());
118 MOCK_CONST_METHOD0(startup_urls, const std::vector<GURL>&());
119 MOCK_CONST_METHOD0(startup_urls_to_reset, const std::vector<GURL>&());
120 MOCK_CONST_METHOD0(startup_urls_reset_state, ResetState());
121 MOCK_CONST_METHOD0(extensions_to_disable, const ExtensionMap&());
122
123 private:
124 static ResetState ChooseResetState(const std::set<SettingType>& settings,
125 SettingType setting) {
126 if (settings.find(setting) != settings.end())
127 return RESET_REQUIRED;
128 return NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED;
129 }
130
131 std::vector<GURL> startup_urls_;
132 std::vector<GURL> startup_urls_to_reset_;
133 ExtensionMap extensions_;
134
135 DISALLOW_COPY_AND_ASSIGN(MockSettingsResetPromptModel);
136 };
137
138 class SettingsResetPromptDialogTest : public DialogBrowserTest {
139 public:
140 void ShowDialog(const std::string& name) override {
141 const std::map<std::string, std::set<SettingType>> name_to_settings = {
142 {"dse", {SettingType::DEFAULT_SEARCH_ENGINE}},
143 {"sp", {SettingType::STARTUP_PAGE}},
144 {"hp", {SettingType::HOMEPAGE}},
145 {"dse_sp",
146 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::STARTUP_PAGE}},
147 {"dse_hp", {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::HOMEPAGE}},
148 {"sp_hp", {SettingType::STARTUP_PAGE, SettingType::HOMEPAGE}},
149 {"dse_sp_hp",
150 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::STARTUP_PAGE,
151 SettingType::HOMEPAGE}},
152 {"dse_ext",
153 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::EXTENSIONS}},
154 {"sp_ext", {SettingType::STARTUP_PAGE, SettingType::EXTENSIONS}},
155 {"hp_ext", {SettingType::HOMEPAGE, SettingType::EXTENSIONS}},
156 {"dse_sp_ext",
157 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::STARTUP_PAGE,
158 SettingType::EXTENSIONS}},
159 {"dse_hp_ext",
160 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::HOMEPAGE,
161 SettingType::EXTENSIONS}},
162 {"sp_hp_ext",
163 {SettingType::STARTUP_PAGE, SettingType::HOMEPAGE,
164 SettingType::EXTENSIONS}},
165 {"dse_sp_hp_ext",
166 {SettingType::DEFAULT_SEARCH_ENGINE, SettingType::STARTUP_PAGE,
167 SettingType::HOMEPAGE, SettingType::EXTENSIONS}}};
168
169 auto model = base::MakeUnique<NiceMock<MockSettingsResetPromptModel>>(
170 browser()->profile(), name_to_settings.find(name)->second);
171
172 safe_browsing::SettingsResetPromptController::ShowSettingsResetPrompt(
173 browser(),
174 new safe_browsing::SettingsResetPromptController(std::move(model)));
175 }
176 };
177
178 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse) {
179 RunDialog();
180 }
181 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_sp) {
182 RunDialog();
183 }
184 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_hp) {
185 RunDialog();
186 }
187 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_sp) {
188 RunDialog();
189 }
190 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_hp) {
191 RunDialog();
192 }
193 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_sp_hp) {
194 RunDialog();
195 }
196 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_sp_hp) {
197 RunDialog();
198 }
199 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_ext) {
200 RunDialog();
201 }
202 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_sp_ext) {
203 RunDialog();
204 }
205 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_hp_ext) {
206 RunDialog();
207 }
208 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_sp_ext) {
209 RunDialog();
210 }
211 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_dse_hp_ext) {
212 RunDialog();
213 }
214 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest, InvokeDialog_sp_hp_ext) {
215 RunDialog();
216 }
217 IN_PROC_BROWSER_TEST_F(SettingsResetPromptDialogTest,
218 InvokeDialog_dse_sp_hp_ext) {
219 RunDialog();
220 }
221
222 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/settings_reset_prompt_dialog.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698