OLD | NEW |
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 | 674 |
675 // For a single Unicode encoded pattern, check if it gets converted to punycode | 675 // For a single Unicode encoded pattern, check if it gets converted to punycode |
676 // and old pattern gets deleted. | 676 // and old pattern gets deleted. |
677 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { | 677 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { |
678 TestingProfile profile; | 678 TestingProfile profile; |
679 PrefService* prefs = profile.GetPrefs(); | 679 PrefService* prefs = profile.GetPrefs(); |
680 | 680 |
681 // Set utf-8 data. | 681 // Set utf-8 data. |
682 { | 682 { |
683 DictionaryPrefUpdate update(prefs, prefs::kContentSettingsPatternPairs); | 683 DictionaryPrefUpdate update( |
| 684 prefs, prefs::kContentSettingsImagesPatternPairs); |
684 base::DictionaryValue* all_settings_dictionary = update.Get(); | 685 base::DictionaryValue* all_settings_dictionary = update.Get(); |
685 ASSERT_TRUE(NULL != all_settings_dictionary); | 686 ASSERT_TRUE(NULL != all_settings_dictionary); |
686 | 687 |
687 base::DictionaryValue* dummy_payload = new base::DictionaryValue; | 688 base::DictionaryValue* dummy_payload = new base::DictionaryValue; |
688 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); | 689 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); |
689 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", | 690 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", |
690 dummy_payload); | 691 dummy_payload); |
691 } | 692 } |
692 profile.GetHostContentSettingsMap(); | 693 profile.GetHostContentSettingsMap(); |
693 | 694 |
694 const base::DictionaryValue* all_settings_dictionary = | 695 const base::DictionaryValue* all_settings_dictionary = |
695 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); | 696 prefs->GetDictionary(prefs::kContentSettingsImagesPatternPairs); |
696 const base::DictionaryValue* result = NULL; | 697 const base::DictionaryValue* result = NULL; |
697 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 698 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
698 "[*.]\xC4\x87ira.com,*", &result)); | 699 "[*.]\xC4\x87ira.com,*", &result)); |
699 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 700 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
700 "[*.]xn--ira-ppa.com,*", &result)); | 701 "[*.]xn--ira-ppa.com,*", &result)); |
701 } | 702 } |
702 | 703 |
703 // If both Unicode and its punycode pattern exist, make sure we don't touch the | 704 // If both Unicode and its punycode pattern exist, make sure we don't touch the |
704 // settings for the punycode, and that Unicode pattern gets deleted. | 705 // settings for the punycode, and that Unicode pattern gets deleted. |
705 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { | 706 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { |
706 TestingProfile profile; | 707 TestingProfile profile; |
707 | 708 |
708 scoped_ptr<base::Value> value(base::JSONReader::Read( | 709 scoped_ptr<base::Value> value(base::JSONReader::Read( |
709 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); | 710 "{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}")); |
710 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); | 711 profile.GetPrefs()->Set(prefs::kContentSettingsImagesPatternPairs, *value); |
711 | 712 |
712 // Set punycode equivalent, with different setting. | 713 // Set punycode equivalent, with different setting. |
713 scoped_ptr<base::Value> puny_value(base::JSONReader::Read( | 714 scoped_ptr<base::Value> puny_value(base::JSONReader::Read( |
714 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); | 715 "{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}")); |
715 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); | 716 profile.GetPrefs()->Set( |
| 717 prefs::kContentSettingsImagesPatternPairs, *puny_value); |
716 | 718 |
717 // Initialize the content map. | 719 // Initialize the content map. |
718 profile.GetHostContentSettingsMap(); | 720 profile.GetHostContentSettingsMap(); |
719 | 721 |
720 const base::DictionaryValue* content_setting_prefs = | 722 const base::DictionaryValue* content_setting_prefs = |
721 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 723 profile.GetPrefs()->GetDictionary( |
| 724 prefs::kContentSettingsImagesPatternPairs); |
722 std::string prefs_as_json; | 725 std::string prefs_as_json; |
723 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); | 726 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
724 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", | 727 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}", |
725 prefs_as_json.c_str()); | 728 prefs_as_json.c_str()); |
726 } | 729 } |
727 | 730 |
728 // If a default-content-setting is managed, the managed value should be used | 731 // If a default-content-setting is managed, the managed value should be used |
729 // instead of the default value. | 732 // instead of the default value. |
730 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { | 733 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { |
731 TestingProfile profile; | 734 TestingProfile profile; |
732 HostContentSettingsMap* host_content_settings_map = | 735 HostContentSettingsMap* host_content_settings_map = |
733 profile.GetHostContentSettingsMap(); | 736 profile.GetHostContentSettingsMap(); |
734 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 737 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 CONTENT_SETTINGS_TYPE_IMAGES, true); | 1065 CONTENT_SETTINGS_TYPE_IMAGES, true); |
1063 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1066 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1064 host_content_settings_map->GetContentSetting( | 1067 host_content_settings_map->GetContentSetting( |
1065 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1068 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
1066 host_content_settings_map->SetDefaultContentSetting( | 1069 host_content_settings_map->SetDefaultContentSetting( |
1067 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 1070 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
1068 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1071 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1069 host_content_settings_map->GetContentSetting( | 1072 host_content_settings_map->GetContentSetting( |
1070 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1073 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
1071 } | 1074 } |
OLD | NEW |