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