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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 1252073002: Move pref names and default value into WebsiteSettingsInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@website-settings-registry-simple
Patch Set: Created 5 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 349 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
350 TestingProfile profile; 350 TestingProfile profile;
351 HostContentSettingsMap* host_content_settings_map = 351 HostContentSettingsMap* host_content_settings_map =
352 profile.GetHostContentSettingsMap(); 352 profile.GetHostContentSettingsMap();
353 353
354 PrefService* prefs = profile.GetPrefs(); 354 PrefService* prefs = profile.GetPrefs();
355 355
356 // Make a copy of the default pref value so we can reset it later. 356 // Make a copy of the default pref value so we can reset it later.
357 scoped_ptr<base::Value> default_value(prefs->FindPreference( 357 scoped_ptr<base::Value> default_value(prefs->FindPreference(
358 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 358 prefs::kContentSettingsImagesPatternPairs)->GetValue()->DeepCopy());
359 359
360 ContentSettingsPattern pattern = 360 ContentSettingsPattern pattern =
361 ContentSettingsPattern::FromString("[*.]example.com"); 361 ContentSettingsPattern::FromString("[*.]example.com");
362 GURL host("http://example.com"); 362 GURL host("http://example.com");
363 363
364 EXPECT_EQ(CONTENT_SETTING_ALLOW, 364 EXPECT_EQ(CONTENT_SETTING_ALLOW,
365 host_content_settings_map->GetContentSetting( 365 host_content_settings_map->GetContentSetting(
366 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 366 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
367 367
368 host_content_settings_map->SetContentSetting( 368 host_content_settings_map->SetContentSetting(
369 pattern, 369 pattern,
370 ContentSettingsPattern::Wildcard(), 370 ContentSettingsPattern::Wildcard(),
371 CONTENT_SETTINGS_TYPE_IMAGES, 371 CONTENT_SETTINGS_TYPE_IMAGES,
372 std::string(), 372 std::string(),
373 CONTENT_SETTING_BLOCK); 373 CONTENT_SETTING_BLOCK);
374 EXPECT_EQ(CONTENT_SETTING_BLOCK, 374 EXPECT_EQ(CONTENT_SETTING_BLOCK,
375 host_content_settings_map->GetContentSetting( 375 host_content_settings_map->GetContentSetting(
376 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 376 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
377 377
378 // Make a copy of the pref's new value so we can reset it later. 378 // Make a copy of the pref's new value so we can reset it later.
379 scoped_ptr<base::Value> new_value(prefs->FindPreference( 379 scoped_ptr<base::Value> new_value(prefs->FindPreference(
380 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 380 prefs::kContentSettingsImagesPatternPairs)->GetValue()->DeepCopy());
381 381
382 // Clearing the backing pref should also clear the internal cache. 382 // Clearing the backing pref should also clear the internal cache.
383 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); 383 prefs->Set(prefs::kContentSettingsImagesPatternPairs, *default_value);
384 EXPECT_EQ(CONTENT_SETTING_ALLOW, 384 EXPECT_EQ(CONTENT_SETTING_ALLOW,
385 host_content_settings_map->GetContentSetting( 385 host_content_settings_map->GetContentSetting(
386 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 386 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
387 387
388 // Reseting the pref to its previous value should update the cache. 388 // Reseting the pref to its previous value should update the cache.
389 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 389 prefs->Set(prefs::kContentSettingsImagesPatternPairs, *new_value);
390 EXPECT_EQ(CONTENT_SETTING_BLOCK, 390 EXPECT_EQ(CONTENT_SETTING_BLOCK,
391 host_content_settings_map->GetContentSetting( 391 host_content_settings_map->GetContentSetting(
392 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 392 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
393 } 393 }
394 394
395 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 395 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
396 TestingProfile profile; 396 TestingProfile profile;
397 HostContentSettingsMap* host_content_settings_map = 397 HostContentSettingsMap* host_content_settings_map =
398 profile.GetHostContentSettingsMap(); 398 profile.GetHostContentSettingsMap();
399 content_settings::CookieSettings* cookie_settings = 399 content_settings::CookieSettings* cookie_settings =
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 666
667 // For a single Unicode encoded pattern, check if it gets converted to punycode 667 // For a single Unicode encoded pattern, check if it gets converted to punycode
668 // and old pattern gets deleted. 668 // and old pattern gets deleted.
669 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 669 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
670 TestingProfile profile; 670 TestingProfile profile;
671 PrefService* prefs = profile.GetPrefs(); 671 PrefService* prefs = profile.GetPrefs();
672 672
673 // Set utf-8 data. 673 // Set utf-8 data.
674 { 674 {
675 DictionaryPrefUpdate update( 675 DictionaryPrefUpdate update(
676 prefs, prefs::kContentSettingsPatternPairs); 676 prefs, prefs::kContentSettingsPluginsPatternPairs);
677 base::DictionaryValue* all_settings_dictionary = update.Get(); 677 base::DictionaryValue* all_settings_dictionary = update.Get();
678 ASSERT_TRUE(NULL != all_settings_dictionary); 678 ASSERT_TRUE(NULL != all_settings_dictionary);
679 679
680 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 680 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
681 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); 681 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
682 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 682 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
683 dummy_payload); 683 dummy_payload);
684 } 684 }
685 685
686 profile.GetHostContentSettingsMap(); 686 profile.GetHostContentSettingsMap();
687 687
688 const base::DictionaryValue* all_settings_dictionary = 688 const base::DictionaryValue* all_settings_dictionary =
689 prefs->GetDictionary(prefs::kContentSettingsImagesPatternPairs); 689 prefs->GetDictionary(prefs::kContentSettingsPluginsPatternPairs);
690 const base::DictionaryValue* result = NULL; 690 const base::DictionaryValue* result = NULL;
691 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 691 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
692 "[*.]\xC4\x87ira.com,*", &result)); 692 "[*.]\xC4\x87ira.com,*", &result));
693 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 693 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
694 "[*.]xn--ira-ppa.com,*", &result)); 694 "[*.]xn--ira-ppa.com,*", &result));
695 } 695 }
696 696
697 // If both Unicode and its punycode pattern exist, make sure we don't touch the 697 // If both Unicode and its punycode pattern exist, make sure we don't touch the
698 // settings for the punycode, and that Unicode pattern gets deleted. 698 // settings for the punycode, and that Unicode pattern gets deleted.
699 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 699 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
700 TestingProfile profile; 700 TestingProfile profile;
701 701
702 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead( 702 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead(
703 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); 703 "{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"));
704 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); 704 profile.GetPrefs()->Set(prefs::kContentSettingsCookiesPatternPairs, *value);
705 705
706 // Set punycode equivalent, with different setting. 706 // Set punycode equivalent, with different setting.
707 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead( 707 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead(
708 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); 708 "{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}"));
709 profile.GetPrefs()->Set( 709 profile.GetPrefs()->Set(
710 prefs::kContentSettingsPatternPairs, *puny_value); 710 prefs::kContentSettingsCookiesPatternPairs, *puny_value);
711 711
712 // Initialize the content map. 712 // Initialize the content map.
713 profile.GetHostContentSettingsMap(); 713 profile.GetHostContentSettingsMap();
714 714
715 const base::DictionaryValue& content_setting_prefs = 715 const base::DictionaryValue& content_setting_prefs =
716 *profile.GetPrefs()->GetDictionary( 716 *profile.GetPrefs()->GetDictionary(
717 prefs::kContentSettingsImagesPatternPairs); 717 prefs::kContentSettingsCookiesPatternPairs);
718 std::string prefs_as_json; 718 std::string prefs_as_json;
719 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); 719 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
720 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}", 720 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}",
721 prefs_as_json.c_str()); 721 prefs_as_json.c_str());
722 } 722 }
723 723
724 // If a default-content-setting is managed, the managed value should be used 724 // If a default-content-setting is managed, the managed value should be used
725 // instead of the default value. 725 // instead of the default value.
726 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { 726 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
727 TestingProfile profile; 727 TestingProfile profile;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1007 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1008 host_content_settings_map->GetContentSetting( 1008 host_content_settings_map->GetContentSetting(
1009 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1009 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1010 host_content_settings_map->SetContentSetting( 1010 host_content_settings_map->SetContentSetting(
1011 pattern, 1011 pattern,
1012 ContentSettingsPattern::Wildcard(), 1012 ContentSettingsPattern::Wildcard(),
1013 CONTENT_SETTINGS_TYPE_IMAGES, 1013 CONTENT_SETTINGS_TYPE_IMAGES,
1014 std::string(), 1014 std::string(),
1015 CONTENT_SETTING_DEFAULT); 1015 CONTENT_SETTING_DEFAULT);
1016 } 1016 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698