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

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

Issue 2946393002: MD Settings: Amend SiteSettingsHandlerTest.Origins to test "Site Details" code. (Closed)
Patch Set: Created 3 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
« 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 "base/test/histogram_tester.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); 92 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
93 EXPECT_EQ("cr.webUIResponse", data.function_name()); 93 EXPECT_EQ("cr.webUIResponse", data.function_name());
94 94
95 std::string callback_id; 95 std::string callback_id;
96 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); 96 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
97 EXPECT_EQ(kCallbackId, callback_id); 97 EXPECT_EQ(kCallbackId, callback_id);
98 bool success = false; 98 bool success = false;
99 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success)); 99 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
100 ASSERT_TRUE(success); 100 ASSERT_TRUE(success);
101 101
102 const base::ListValue* exceptions;
103 ASSERT_TRUE(data.arg3()->GetAsList(&exceptions));
104 EXPECT_EQ(1U, exceptions->GetSize());
105 const base::DictionaryValue* exception; 102 const base::DictionaryValue* exception;
106 ASSERT_TRUE(exceptions->GetDictionary(0, &exception)); 103 if (data.arg3()->is_list()) {
104 const base::ListValue* exceptions;
105 ASSERT_TRUE(data.arg3()->GetAsList(&exceptions));
106 EXPECT_EQ(1U, exceptions->GetSize());
107 ASSERT_TRUE(exceptions->GetDictionary(0, &exception));
108 } else {
109 data.arg3()->GetAsDictionary(&exception);
raymes 2017/06/26 04:12:27 Could you add a comment describing these 2 cases?
Patti Lor 2017/06/26 08:10:54 Done.
110 }
107 std::string origin, embedding_origin, display_name, setting, source; 111 std::string origin, embedding_origin, display_name, setting, source;
108 ASSERT_TRUE(exception->GetString(site_settings::kOrigin, &origin)); 112 ASSERT_TRUE(exception->GetString(site_settings::kOrigin, &origin));
109 ASSERT_EQ(expected_origin, origin); 113 ASSERT_EQ(expected_origin, origin);
110 ASSERT_TRUE( 114 ASSERT_TRUE(
111 exception->GetString(site_settings::kDisplayName, &display_name)); 115 exception->GetString(site_settings::kDisplayName, &display_name));
112 ASSERT_EQ(expected_display_name, display_name); 116 ASSERT_EQ(expected_display_name, display_name);
113 ASSERT_TRUE(exception->GetString( 117 ASSERT_TRUE(exception->GetString(
114 site_settings::kEmbeddingOrigin, &embedding_origin)); 118 site_settings::kEmbeddingOrigin, &embedding_origin));
115 ASSERT_EQ(expected_embedding, embedding_origin); 119 ASSERT_EQ(expected_embedding, embedding_origin);
116 ASSERT_TRUE(exception->GetString(site_settings::kSetting, &setting)); 120 ASSERT_TRUE(exception->GetString(site_settings::kSetting, &setting));
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 set_args.AppendBoolean(false); // Incognito. 269 set_args.AppendBoolean(false); // Incognito.
266 base::HistogramTester histograms; 270 base::HistogramTester histograms;
267 handler()->HandleSetCategoryPermissionForOrigin(&set_args); 271 handler()->HandleSetCategoryPermissionForOrigin(&set_args);
268 EXPECT_EQ(1U, web_ui()->call_data().size()); 272 EXPECT_EQ(1U, web_ui()->call_data().size());
269 histograms.ExpectTotalCount(kUmaBase, 1); 273 histograms.ExpectTotalCount(kUmaBase, 1);
270 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0); 274 histograms.ExpectTotalCount(kUmaBase + ".Allowed", 0);
271 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1); 275 histograms.ExpectTotalCount(kUmaBase + ".Blocked", 1);
272 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0); 276 histograms.ExpectTotalCount(kUmaBase + ".Reset", 0);
273 } 277 }
274 278
275 // Verify the change was successful. 279 // If the change was successful, it should show up as an exception as well as
276 base::ListValue listArgs; 280 // in the response for a specific request to getCategoryPermissionForOrigin.
277 listArgs.AppendString(kCallbackId); 281 // Check getCategoryPermissionForOrigin.
278 listArgs.AppendString("notifications"); 282 base::ListValue getCategoryPermissionArgs;
279 handler()->HandleGetExceptionList(&listArgs); 283 getCategoryPermissionArgs.AppendString(kCallbackId);
284 getCategoryPermissionArgs.AppendString("notifications");
285 getCategoryPermissionArgs.AppendString(google);
286 handler()->HandleGetCategoryPermissionForOrigin(&getCategoryPermissionArgs);
280 ValidateOrigin(google, google, google, "block", "preference", 2U); 287 ValidateOrigin(google, google, google, "block", "preference", 2U);
281 288
289 // Check getExceptionList.
290 base::ListValue getExceptionListArgs;
291 getExceptionListArgs.AppendString(kCallbackId);
292 getExceptionListArgs.AppendString("notifications");
293 handler()->HandleGetExceptionList(&getExceptionListArgs);
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(&getExceptionListArgs);
300 ValidateNoOrigin(4U); 314 ValidateNoOrigin(5U);
315
316 handler()->HandleGetCategoryPermissionForOrigin(&getCategoryPermissionArgs);
317 // Ask is the currently the built-in Chrome default 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
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
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