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

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

Issue 2021343003: MD Site Settings: Add five new top level categories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback and add icons Created 4 years, 6 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
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/settings/site_settings_handler.h" 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "chrome/browser/ui/webui/site_settings_helper.h" 9 #include "chrome/browser/ui/webui/site_settings_helper.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 private: 132 private:
133 content::TestBrowserThreadBundle thread_bundle_; 133 content::TestBrowserThreadBundle thread_bundle_;
134 TestingProfile profile_; 134 TestingProfile profile_;
135 content::TestWebUI web_ui_; 135 content::TestWebUI web_ui_;
136 SiteSettingsHandler handler_; 136 SiteSettingsHandler handler_;
137 }; 137 };
138 138
139 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { 139 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) {
140 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
141
142 // Test the JS -> C++ -> JS callback path for getting and setting defaults. 140 // Test the JS -> C++ -> JS callback path for getting and setting defaults.
143 base::ListValue getArgs; 141 base::ListValue getArgs;
144 getArgs.AppendString(kCallbackId); 142 getArgs.AppendString(kCallbackId);
145 getArgs.AppendInteger(type); 143 getArgs.AppendString("notifications");
146 handler()->HandleGetDefaultValueForContentType(&getArgs); 144 handler()->HandleGetDefaultValueForContentType(&getArgs);
147 ValidateDefault(true, 1U); 145 ValidateDefault(true, 1U);
148 146
149 // Set the default to 'Blocked'. 147 // Set the default to 'Blocked'.
150 base::ListValue setArgs; 148 base::ListValue setArgs;
151 setArgs.AppendInteger(type); 149 setArgs.AppendString("notifications");
152 setArgs.AppendString("block"); 150 setArgs.AppendString("block");
153 handler()->HandleSetDefaultValueForContentType(&setArgs); 151 handler()->HandleSetDefaultValueForContentType(&setArgs);
154 152
155 EXPECT_EQ(2U, web_ui()->call_data().size()); 153 EXPECT_EQ(2U, web_ui()->call_data().size());
156 154
157 // Verify that the default has been set to 'Blocked'. 155 // Verify that the default has been set to 'Blocked'.
158 handler()->HandleGetDefaultValueForContentType(&getArgs); 156 handler()->HandleGetDefaultValueForContentType(&getArgs);
159 ValidateDefault(false, 3U); 157 ValidateDefault(false, 3U);
160 } 158 }
161 159
162 TEST_F(SiteSettingsHandlerTest, Origins) { 160 TEST_F(SiteSettingsHandlerTest, Origins) {
163 ContentSettingsType type = CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
164
165 // Test the JS -> C++ -> JS callback path for configuring origins, by setting 161 // Test the JS -> C++ -> JS callback path for configuring origins, by setting
166 // Google.com to blocked. 162 // Google.com to blocked.
167 base::ListValue setArgs; 163 base::ListValue setArgs;
168 std::string google("http://www.google.com"); 164 std::string google("http://www.google.com");
169 setArgs.AppendString(google); // Primary pattern. 165 setArgs.AppendString(google); // Primary pattern.
170 setArgs.AppendString(google); // Secondary pattern. 166 setArgs.AppendString(google); // Secondary pattern.
171 setArgs.AppendInteger(type); 167 setArgs.AppendString("notifications");
172 setArgs.AppendString("block"); 168 setArgs.AppendString("block");
173 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); 169 handler()->HandleSetCategoryPermissionForOrigin(&setArgs);
174 EXPECT_EQ(1U, web_ui()->call_data().size()); 170 EXPECT_EQ(1U, web_ui()->call_data().size());
175 171
176 // Verify the change was successful. 172 // Verify the change was successful.
177 base::ListValue listArgs; 173 base::ListValue listArgs;
178 listArgs.AppendString(kCallbackId); 174 listArgs.AppendString(kCallbackId);
179 listArgs.AppendInteger(type); 175 listArgs.AppendString("notifications");
180 handler()->HandleGetExceptionList(&listArgs); 176 handler()->HandleGetExceptionList(&listArgs);
181 ValidateOrigin(google, google, "block", "preference", 2U); 177 ValidateOrigin(google, google, "block", "preference", 2U);
182 178
183 // Reset things back to how they were. 179 // Reset things back to how they were.
184 base::ListValue resetArgs; 180 base::ListValue resetArgs;
185 resetArgs.AppendString(google); 181 resetArgs.AppendString(google);
186 resetArgs.AppendString(google); 182 resetArgs.AppendString(google);
187 resetArgs.AppendInteger(type); 183 resetArgs.AppendString("notifications");
188 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); 184 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs);
189 EXPECT_EQ(3U, web_ui()->call_data().size()); 185 EXPECT_EQ(3U, web_ui()->call_data().size());
190 186
191 // Verify the reset was successful. 187 // Verify the reset was successful.
192 handler()->HandleGetExceptionList(&listArgs); 188 handler()->HandleGetExceptionList(&listArgs);
193 ValidateNoOrigin(4U); 189 ValidateNoOrigin(4U);
194 } 190 }
195 191
196 TEST_F(SiteSettingsHandlerTest, Patterns) { 192 TEST_F(SiteSettingsHandlerTest, Patterns) {
197 base::ListValue args; 193 base::ListValue args;
198 std::string pattern("[*.]google.com"); 194 std::string pattern("[*.]google.com");
199 args.AppendString(kCallbackId); 195 args.AppendString(kCallbackId);
200 args.AppendString(pattern); 196 args.AppendString(pattern);
201 handler()->HandleIsPatternValid(&args); 197 handler()->HandleIsPatternValid(&args);
202 ValidatePattern(true, 1U); 198 ValidatePattern(true, 1U);
203 199
204 base::ListValue invalid; 200 base::ListValue invalid;
205 std::string bad_pattern(";"); 201 std::string bad_pattern(";");
206 invalid.AppendString(kCallbackId); 202 invalid.AppendString(kCallbackId);
207 invalid.AppendString(bad_pattern); 203 invalid.AppendString(bad_pattern);
208 handler()->HandleIsPatternValid(&invalid); 204 handler()->HandleIsPatternValid(&invalid);
209 ValidatePattern(false, 2U); 205 ValidatePattern(false, 2U);
210 } 206 }
211 207
212 } // namespace settings 208 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/site_settings_handler.cc ('k') | chrome/browser/ui/webui/site_settings_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698