Chromium Code Reviews| 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 "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/webui/site_settings_helper.h" | 11 #include "chrome/browser/ui/webui/site_settings_helper.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/content_settings/core/common/content_settings.h" | 13 #include "components/content_settings/core/common/content_settings.h" |
| 13 #include "components/content_settings/core/common/content_settings_types.h" | 14 #include "components/content_settings/core/common/content_settings_types.h" |
| 14 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 15 #include "content/public/browser/web_ui_data_source.h" | 16 #include "content/public/browser/web_ui_data_source.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "content/public/test/test_web_ui.h" | 18 #include "content/public/test/test_web_ui.h" |
| 18 #include "extensions/common/extension_builder.h" | 19 #include "extensions/common/extension_builder.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 EXPECT_EQ(2U, web_ui()->call_data().size()); | 247 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 247 | 248 |
| 248 // Verify that the default has been set to 'Blocked'. | 249 // Verify that the default has been set to 'Blocked'. |
| 249 handler()->HandleGetDefaultValueForContentType(&getArgs); | 250 handler()->HandleGetDefaultValueForContentType(&getArgs); |
| 250 ValidateDefault("block", "default", 3U); | 251 ValidateDefault("block", "default", 3U); |
| 251 } | 252 } |
| 252 | 253 |
| 253 TEST_F(SiteSettingsHandlerTest, Origins) { | 254 TEST_F(SiteSettingsHandlerTest, Origins) { |
| 254 // 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 |
| 255 // Google.com to blocked. | 256 // Google.com to blocked. |
| 256 base::ListValue setArgs; | 257 base::ListValue setArgs; |
|
Dan Beam
2017/05/05 01:40:48
nit maybe for a followup: all of the args things s
dschuyler
2017/05/05 21:21:35
Done.
| |
| 257 std::string google("http://www.google.com"); | 258 std::string google("http://www.google.com"); |
| 258 setArgs.AppendString(google); // Primary pattern. | 259 setArgs.AppendString(google); // Primary pattern. |
| 259 setArgs.AppendString(google); // Secondary pattern. | 260 setArgs.AppendString(google); // Secondary pattern. |
| 260 setArgs.AppendString("notifications"); | 261 setArgs.AppendString("notifications"); |
| 261 setArgs.AppendString("block"); | 262 setArgs.AppendString("block"); |
| 262 setArgs.AppendBoolean(false); // Incognito. | 263 setArgs.AppendBoolean(false); // Incognito. |
| 264 base::HistogramTester histograms; | |
| 263 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); | 265 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); |
| 264 EXPECT_EQ(1U, web_ui()->call_data().size()); | 266 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 267 const std::string kUmaBase("WebsiteSettings.Menu.PermissionChanged"); | |
| 268 histograms.ExpectTotalCount(kUmaBase, 1); | |
| 269 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); | |
| 270 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1); | |
| 271 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0); | |
| 265 | 272 |
| 266 // Verify the change was successful. | 273 // Verify the change was successful. |
| 267 base::ListValue listArgs; | 274 base::ListValue listArgs; |
| 268 listArgs.AppendString(kCallbackId); | 275 listArgs.AppendString(kCallbackId); |
| 269 listArgs.AppendString("notifications"); | 276 listArgs.AppendString("notifications"); |
| 270 handler()->HandleGetExceptionList(&listArgs); | 277 handler()->HandleGetExceptionList(&listArgs); |
| 271 ValidateOrigin(google, google, google, "block", "preference", 2U); | 278 ValidateOrigin(google, google, google, "block", "preference", 2U); |
| 272 | 279 |
| 273 // Reset things back to how they were. | 280 // Reset things back to how they were. |
| 274 base::ListValue resetArgs; | 281 base::ListValue resetArgs; |
| 275 resetArgs.AppendString(google); | 282 resetArgs.AppendString(google); |
| 276 resetArgs.AppendString(google); | 283 resetArgs.AppendString(google); |
| 277 resetArgs.AppendString("notifications"); | 284 resetArgs.AppendString("notifications"); |
| 278 resetArgs.AppendBoolean(false); // Incognito. | 285 resetArgs.AppendBoolean(false); // Incognito. |
| 279 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); | 286 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); |
| 280 EXPECT_EQ(3U, web_ui()->call_data().size()); | 287 EXPECT_EQ(3U, web_ui()->call_data().size()); |
| 288 histograms.ExpectTotalCount(kUmaBase, 2); // Including the "block" above. | |
|
Dan Beam
2017/05/05 01:40:48
nit: you could just make a new scope
{
base::Hi
dschuyler
2017/05/05 21:21:35
Done.
| |
| 289 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); | |
| 290 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1); | |
| 291 histograms.ExpectTotalCount(kUmaBase + ".Reset", 1); | |
| 281 | 292 |
| 282 // Verify the reset was successful. | 293 // Verify the reset was successful. |
| 283 handler()->HandleGetExceptionList(&listArgs); | 294 handler()->HandleGetExceptionList(&listArgs); |
| 284 ValidateNoOrigin(4U); | 295 ValidateNoOrigin(4U); |
| 285 } | 296 } |
| 286 | 297 |
| 287 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { | 298 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { |
| 288 ContentSettingsPattern pattern = | 299 ContentSettingsPattern pattern = |
| 289 ContentSettingsPattern::FromString("[*.]google.com"); | 300 ContentSettingsPattern::FromString("[*.]google.com"); |
| 290 std::unique_ptr<base::DictionaryValue> exception = | 301 std::unique_ptr<base::DictionaryValue> exception = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 args.AppendString("http://www.google.com"); | 404 args.AppendString("http://www.google.com"); |
| 394 handler()->HandleRemoveZoomLevel(&args); | 405 handler()->HandleRemoveZoomLevel(&args); |
| 395 ValidateZoom("", "", 3U); | 406 ValidateZoom("", "", 3U); |
| 396 | 407 |
| 397 double default_level = host_zoom_map->GetDefaultZoomLevel(); | 408 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 398 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); | 409 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); |
| 399 EXPECT_EQ(default_level, level); | 410 EXPECT_EQ(default_level, level); |
| 400 } | 411 } |
| 401 | 412 |
| 402 } // namespace settings | 413 } // namespace settings |
| OLD | NEW |