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

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

Issue 2862183002: [MD settings] test UMA when changing site settings exceptions (Closed)
Patch Set: review changs Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 const std::string google("http://www.google.com");
257 std::string google("http://www.google.com"); 258 const std::string kUmaBase("WebsiteSettings.Menu.PermissionChanged");
258 setArgs.AppendString(google); // Primary pattern. 259 {
259 setArgs.AppendString(google); // Secondary pattern. 260 base::ListValue set_args;
260 setArgs.AppendString("notifications"); 261 set_args.AppendString(google); // Primary pattern.
261 setArgs.AppendString("block"); 262 set_args.AppendString(google); // Secondary pattern.
262 setArgs.AppendBoolean(false); // Incognito. 263 set_args.AppendString("notifications");
263 handler()->HandleSetCategoryPermissionForOrigin(&setArgs); 264 set_args.AppendString("block");
264 EXPECT_EQ(1U, web_ui()->call_data().size()); 265 set_args.AppendBoolean(false); // Incognito.
266 base::HistogramTester histograms;
267 handler()->HandleSetCategoryPermissionForOrigin(&set_args);
268 EXPECT_EQ(1U, web_ui()->call_data().size());
269 histograms.ExpectTotalCount(kUmaBase, 1);
270 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0);
271 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1);
272 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0);
273 }
265 274
266 // Verify the change was successful. 275 // Verify the change was successful.
267 base::ListValue listArgs; 276 base::ListValue listArgs;
268 listArgs.AppendString(kCallbackId); 277 listArgs.AppendString(kCallbackId);
269 listArgs.AppendString("notifications"); 278 listArgs.AppendString("notifications");
270 handler()->HandleGetExceptionList(&listArgs); 279 handler()->HandleGetExceptionList(&listArgs);
271 ValidateOrigin(google, google, google, "block", "preference", 2U); 280 ValidateOrigin(google, google, google, "block", "preference", 2U);
272 281
273 // Reset things back to how they were. 282 {
274 base::ListValue resetArgs; 283 // Reset things back to how they were.
275 resetArgs.AppendString(google); 284 base::ListValue reset_args;
276 resetArgs.AppendString(google); 285 reset_args.AppendString(google);
277 resetArgs.AppendString("notifications"); 286 reset_args.AppendString(google);
278 resetArgs.AppendBoolean(false); // Incognito. 287 reset_args.AppendString("notifications");
279 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); 288 reset_args.AppendBoolean(false); // Incognito.
280 EXPECT_EQ(3U, web_ui()->call_data().size()); 289 base::HistogramTester histograms;
290 handler()->HandleResetCategoryPermissionForOrigin(&reset_args);
291 EXPECT_EQ(3U, web_ui()->call_data().size());
292 histograms.ExpectTotalCount(kUmaBase, 1);
293 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0);
294 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 0);
295 histograms.ExpectTotalCount(kUmaBase + ".Reset", 1);
296 }
281 297
282 // Verify the reset was successful. 298 // Verify the reset was successful.
283 handler()->HandleGetExceptionList(&listArgs); 299 handler()->HandleGetExceptionList(&listArgs);
284 ValidateNoOrigin(4U); 300 ValidateNoOrigin(4U);
285 } 301 }
286 302
287 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { 303 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) {
288 ContentSettingsPattern pattern = 304 ContentSettingsPattern pattern =
289 ContentSettingsPattern::FromString("[*.]google.com"); 305 ContentSettingsPattern::FromString("[*.]google.com");
290 std::unique_ptr<base::DictionaryValue> exception = 306 std::unique_ptr<base::DictionaryValue> exception =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 args.AppendString("http://www.google.com"); 409 args.AppendString("http://www.google.com");
394 handler()->HandleRemoveZoomLevel(&args); 410 handler()->HandleRemoveZoomLevel(&args);
395 ValidateZoom("", "", 3U); 411 ValidateZoom("", "", 3U);
396 412
397 double default_level = host_zoom_map->GetDefaultZoomLevel(); 413 double default_level = host_zoom_map->GetDefaultZoomLevel();
398 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); 414 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host);
399 EXPECT_EQ(default_level, level); 415 EXPECT_EQ(default_level, level);
400 } 416 }
401 417
402 } // namespace settings 418 } // namespace settings
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698