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/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 "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 content::TestWebUI web_ui_; | 225 content::TestWebUI web_ui_; |
226 SiteSettingsHandler handler_; | 226 SiteSettingsHandler handler_; |
227 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
228 chromeos::MockUserManager* mock_user_manager_; // Not owned. | 228 chromeos::MockUserManager* mock_user_manager_; // Not owned. |
229 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 229 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
230 #endif | 230 #endif |
231 }; | 231 }; |
232 | 232 |
233 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { | 233 TEST_F(SiteSettingsHandlerTest, GetAndSetDefault) { |
234 // Test the JS -> C++ -> JS callback path for getting and setting defaults. | 234 // Test the JS -> C++ -> JS callback path for getting and setting defaults. |
235 base::ListValue getArgs; | 235 base::ListValue get_args; |
236 getArgs.AppendString(kCallbackId); | 236 get_args.AppendString(kCallbackId); |
237 getArgs.AppendString("notifications"); | 237 get_args.AppendString("notifications"); |
238 handler()->HandleGetDefaultValueForContentType(&getArgs); | 238 handler()->HandleGetDefaultValueForContentType(&get_args); |
239 ValidateDefault("ask", "default", 1U); | 239 ValidateDefault("ask", "default", 1U); |
240 | 240 |
241 // Set the default to 'Blocked'. | 241 // Set the default to 'Blocked'. |
242 base::ListValue setArgs; | 242 base::ListValue set_args; |
243 setArgs.AppendString("notifications"); | 243 set_args.AppendString("notifications"); |
244 setArgs.AppendString("block"); | 244 set_args.AppendString("block"); |
245 handler()->HandleSetDefaultValueForContentType(&setArgs); | 245 handler()->HandleSetDefaultValueForContentType(&set_args); |
246 | 246 |
247 EXPECT_EQ(2U, web_ui()->call_data().size()); | 247 EXPECT_EQ(2U, web_ui()->call_data().size()); |
248 | 248 |
249 // Verify that the default has been set to 'Blocked'. | 249 // Verify that the default has been set to 'Blocked'. |
250 handler()->HandleGetDefaultValueForContentType(&getArgs); | 250 handler()->HandleGetDefaultValueForContentType(&get_args); |
251 ValidateDefault("block", "default", 3U); | 251 ValidateDefault("block", "default", 3U); |
252 } | 252 } |
253 | 253 |
254 TEST_F(SiteSettingsHandlerTest, Origins) { | 254 TEST_F(SiteSettingsHandlerTest, Origins) { |
255 // Test the JS -> C++ -> JS callback path for configuring origins, by setting | 255 // Test the JS -> C++ -> JS callback path for configuring origins, by setting |
256 // Google.com to blocked. | 256 // Google.com to blocked. |
257 const std::string google("http://www.google.com"); | 257 const std::string google("http://www.google.com"); |
258 const std::string kUmaBase("WebsiteSettings.Menu.PermissionChanged"); | 258 const std::string kUmaBase("WebsiteSettings.Menu.PermissionChanged"); |
259 { | 259 { |
260 base::ListValue set_args; | 260 base::ListValue set_args; |
261 set_args.AppendString(google); // Primary pattern. | 261 set_args.AppendString(google); // Primary pattern. |
262 set_args.AppendString(google); // Secondary pattern. | 262 set_args.AppendString(google); // Secondary pattern. |
263 set_args.AppendString("notifications"); | 263 set_args.AppendString("notifications"); |
264 set_args.AppendString("block"); | 264 set_args.AppendString("block"); |
265 set_args.AppendBoolean(false); // Incognito. | 265 set_args.AppendBoolean(false); // Incognito. |
266 base::HistogramTester histograms; | 266 base::HistogramTester histograms; |
267 handler()->HandleSetCategoryPermissionForOrigin(&set_args); | 267 handler()->HandleSetCategoryPermissionForOrigin(&set_args); |
268 EXPECT_EQ(1U, web_ui()->call_data().size()); | 268 EXPECT_EQ(1U, web_ui()->call_data().size()); |
269 histograms.ExpectTotalCount(kUmaBase, 1); | 269 histograms.ExpectTotalCount(kUmaBase, 1); |
270 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); | 270 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); |
271 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1); | 271 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1); |
272 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0); | 272 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0); |
273 } | 273 } |
274 | 274 |
275 // Verify the change was successful. | 275 // If the change was successful, it should show up in the response from |
276 base::ListValue listArgs; | 276 // getExceptionList() as well as getOriginPermissions(). |
277 listArgs.AppendString(kCallbackId); | 277 // Check getOriginPermissions(). |
278 listArgs.AppendString("notifications"); | 278 base::ListValue get_origin_permissions_args; |
279 handler()->HandleGetExceptionList(&listArgs); | 279 get_origin_permissions_args.AppendString(kCallbackId); |
| 280 get_origin_permissions_args.AppendString(google); |
| 281 { |
| 282 auto category_list = base::MakeUnique<base::ListValue>(); |
| 283 category_list->AppendString("notifications"); |
| 284 get_origin_permissions_args.Append(std::move(category_list)); |
| 285 } |
| 286 handler()->HandleGetOriginPermissions(&get_origin_permissions_args); |
280 ValidateOrigin(google, google, google, "block", "preference", 2U); | 287 ValidateOrigin(google, google, google, "block", "preference", 2U); |
281 | 288 |
| 289 // Check getExceptionList(). |
| 290 base::ListValue get_exception_list_args; |
| 291 get_exception_list_args.AppendString(kCallbackId); |
| 292 get_exception_list_args.AppendString("notifications"); |
| 293 handler()->HandleGetExceptionList(&get_exception_list_args); |
| 294 ValidateOrigin(google, google, google, "block", "preference", 3U); |
| 295 |
282 { | 296 { |
283 // Reset things back to how they were. | 297 // Reset things back to how they were. |
284 base::ListValue reset_args; | 298 base::ListValue reset_args; |
285 reset_args.AppendString(google); | 299 reset_args.AppendString(google); |
286 reset_args.AppendString(google); | 300 reset_args.AppendString(google); |
287 reset_args.AppendString("notifications"); | 301 reset_args.AppendString("notifications"); |
288 reset_args.AppendBoolean(false); // Incognito. | 302 reset_args.AppendBoolean(false); // Incognito. |
289 base::HistogramTester histograms; | 303 base::HistogramTester histograms; |
290 handler()->HandleResetCategoryPermissionForOrigin(&reset_args); | 304 handler()->HandleResetCategoryPermissionForOrigin(&reset_args); |
291 EXPECT_EQ(3U, web_ui()->call_data().size()); | 305 EXPECT_EQ(4U, web_ui()->call_data().size()); |
292 histograms.ExpectTotalCount(kUmaBase, 1); | 306 histograms.ExpectTotalCount(kUmaBase, 1); |
293 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); | 307 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); |
294 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 0); | 308 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 0); |
295 histograms.ExpectTotalCount(kUmaBase + ".Reset", 1); | 309 histograms.ExpectTotalCount(kUmaBase + ".Reset", 1); |
296 } | 310 } |
297 | 311 |
298 // Verify the reset was successful. | 312 // Verify the reset was successful. |
299 handler()->HandleGetExceptionList(&listArgs); | 313 handler()->HandleGetExceptionList(&get_exception_list_args); |
300 ValidateNoOrigin(4U); | 314 ValidateNoOrigin(5U); |
| 315 |
| 316 handler()->HandleGetOriginPermissions(&get_origin_permissions_args); |
| 317 // "Ask" is the default value for Notifications. |
| 318 ValidateOrigin(google, google, google, "ask", "preference", 6U); |
301 } | 319 } |
302 | 320 |
303 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { | 321 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { |
304 ContentSettingsPattern pattern = | 322 ContentSettingsPattern pattern = |
305 ContentSettingsPattern::FromString("[*.]google.com"); | 323 ContentSettingsPattern::FromString("[*.]google.com"); |
306 std::unique_ptr<base::DictionaryValue> exception = | 324 std::unique_ptr<base::DictionaryValue> exception = |
307 site_settings::GetExceptionForPage(pattern, pattern, pattern.ToString(), | 325 site_settings::GetExceptionForPage(pattern, pattern, pattern.ToString(), |
308 CONTENT_SETTING_BLOCK, "preference", | 326 CONTENT_SETTING_BLOCK, "preference", |
309 false); | 327 false); |
310 | 328 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 args.AppendString("http://www.google.com"); | 427 args.AppendString("http://www.google.com"); |
410 handler()->HandleRemoveZoomLevel(&args); | 428 handler()->HandleRemoveZoomLevel(&args); |
411 ValidateZoom("", "", 3U); | 429 ValidateZoom("", "", 3U); |
412 | 430 |
413 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 431 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
414 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); | 432 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); |
415 EXPECT_EQ(default_level, level); | 433 EXPECT_EQ(default_level, level); |
416 } | 434 } |
417 | 435 |
418 } // namespace settings | 436 } // namespace settings |
OLD | NEW |