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

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

Issue 2350303004: Site Settings Desktop: Fix crash when altering exception. (Closed)
Patch Set: Address feedback Created 4 years, 3 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/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/ui/webui/site_settings_helper.h" 10 #include "chrome/browser/ui/webui/site_settings_helper.h"
11 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "components/content_settings/core/common/content_settings.h" 12 #include "components/content_settings/core/common/content_settings.h"
13 #include "components/content_settings/core/common/content_settings_types.h" 13 #include "components/content_settings/core/common/content_settings_types.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_ui_data_source.h" 15 #include "content/public/browser/web_ui_data_source.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_web_ui.h" 17 #include "content/public/test/test_web_ui.h"
18 #include "extensions/common/extension_builder.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace { 21 namespace {
21 22
22 const char kCallbackId[] = "test-callback-id"; 23 const char kCallbackId[] = "test-callback-id";
23 24
24 } 25 }
25 26
26 namespace settings { 27 namespace settings {
27 28
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 resetArgs.AppendString("notifications"); 250 resetArgs.AppendString("notifications");
250 resetArgs.AppendBoolean(false); // Incognito. 251 resetArgs.AppendBoolean(false); // Incognito.
251 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs); 252 handler()->HandleResetCategoryPermissionForOrigin(&resetArgs);
252 EXPECT_EQ(3U, web_ui()->call_data().size()); 253 EXPECT_EQ(3U, web_ui()->call_data().size());
253 254
254 // Verify the reset was successful. 255 // Verify the reset was successful.
255 handler()->HandleGetExceptionList(&listArgs); 256 handler()->HandleGetExceptionList(&listArgs);
256 ValidateNoOrigin(4U); 257 ValidateNoOrigin(4U);
257 } 258 }
258 259
260 TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) {
261 ContentSettingsPattern pattern =
262 ContentSettingsPattern::FromString("[*.]google.com");
263 std::unique_ptr<base::DictionaryValue> exception =
264 site_settings::GetExceptionForPage(pattern, pattern,
265 CONTENT_SETTING_BLOCK, "preference", false);
266
267 std::string primary_pattern, secondary_pattern, type;
268 bool incognito;
269 CHECK(exception->GetString(site_settings::kOrigin, &primary_pattern));
270 CHECK(exception->GetString(site_settings::kEmbeddingOrigin,
271 &secondary_pattern));
272 CHECK(exception->GetString(site_settings::kSetting, &type));
273 CHECK(exception->GetBoolean(site_settings::kIncognito, &incognito));
274
275 base::ListValue args;
276 args.AppendString(primary_pattern);
277 args.AppendString(secondary_pattern);
278 args.AppendString("notifications"); // Chosen arbitrarily.
279 args.AppendString(type);
280 args.AppendBoolean(incognito);
281
282 // We don't need to check the results. This is just to make sure it doesn't
283 // crash on the input.
284 handler()->HandleSetCategoryPermissionForOrigin(&args);
285
286 scoped_refptr<const extensions::Extension> extension;
287 extension = extensions::ExtensionBuilder()
288 .SetManifest(extensions::DictionaryBuilder()
289 .Set("name", "Test extension")
290 .Set("version", "1.0.0")
291 .Set("manifest_version", 2)
292 .Build())
293 .SetID("ahfgeienlihckogmohjhadlkjgocpleb")
294 .Build();
295
296 std::unique_ptr<base::ListValue> exceptions(new base::ListValue);
297 site_settings::AddExceptionForHostedApp(
298 "[*.]google.com", *extension.get(), exceptions.get());
299
300 const base::DictionaryValue* dictionary;
301 CHECK(exceptions->GetDictionary(0, &dictionary));
302 CHECK(dictionary->GetString(site_settings::kOrigin, &primary_pattern));
303 CHECK(dictionary->GetString(site_settings::kEmbeddingOrigin,
304 &secondary_pattern));
305 CHECK(dictionary->GetString(site_settings::kSetting, &type));
306 CHECK(dictionary->GetBoolean(site_settings::kIncognito, &incognito));
307
308 // Again, don't need to check the results.
309 handler()->HandleSetCategoryPermissionForOrigin(&args);
310 }
311
259 TEST_F(SiteSettingsHandlerTest, Patterns) { 312 TEST_F(SiteSettingsHandlerTest, Patterns) {
260 base::ListValue args; 313 base::ListValue args;
261 std::string pattern("[*.]google.com"); 314 std::string pattern("[*.]google.com");
262 args.AppendString(kCallbackId); 315 args.AppendString(kCallbackId);
263 args.AppendString(pattern); 316 args.AppendString(pattern);
264 handler()->HandleIsPatternValid(&args); 317 handler()->HandleIsPatternValid(&args);
265 ValidatePattern(true, 1U); 318 ValidatePattern(true, 1U);
266 319
267 base::ListValue invalid; 320 base::ListValue invalid;
268 std::string bad_pattern(";"); 321 std::string bad_pattern(";");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 args.AppendString("http://www.google.com"); 353 args.AppendString("http://www.google.com");
301 handler()->HandleRemoveZoomLevel(&args); 354 handler()->HandleRemoveZoomLevel(&args);
302 ValidateZoom("", "", 3U); 355 ValidateZoom("", "", 3U);
303 356
304 double default_level = host_zoom_map->GetDefaultZoomLevel(); 357 double default_level = host_zoom_map->GetDefaultZoomLevel();
305 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); 358 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host);
306 EXPECT_EQ(default_level, level); 359 EXPECT_EQ(default_level, level);
307 } 360 }
308 361
309 } // namespace settings 362 } // 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