| 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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 profile.GetHostContentSettingsMap(); | 708 profile.GetHostContentSettingsMap(); |
| 709 | 709 |
| 710 const DictionaryValue* content_setting_prefs = | 710 const DictionaryValue* content_setting_prefs = |
| 711 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 711 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 712 std::string prefs_as_json; | 712 std::string prefs_as_json; |
| 713 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); | 713 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
| 714 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", | 714 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", |
| 715 prefs_as_json.c_str()); | 715 prefs_as_json.c_str()); |
| 716 } | 716 } |
| 717 | 717 |
| 718 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { | |
| 719 // This feature is currently behind a flag. | |
| 720 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
| 721 base::AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
| 722 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | |
| 723 | |
| 724 TestingProfile profile; | |
| 725 HostContentSettingsMap* host_content_settings_map = | |
| 726 profile.GetHostContentSettingsMap(); | |
| 727 | |
| 728 GURL host("http://example.com/"); | |
| 729 ContentSettingsPattern pattern = | |
| 730 ContentSettingsPattern::FromString("[*.]example.com"); | |
| 731 std::string resource1("someplugin"); | |
| 732 std::string resource2("otherplugin"); | |
| 733 | |
| 734 // If resource content settings are enabled, GetContentSettings should return | |
| 735 // the default values for all plugins | |
| 736 ContentSetting default_plugin_setting = | |
| 737 host_content_settings_map->GetDefaultContentSetting( | |
| 738 CONTENT_SETTINGS_TYPE_PLUGINS, NULL); | |
| 739 EXPECT_EQ(default_plugin_setting, | |
| 740 host_content_settings_map->GetContentSetting( | |
| 741 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); | |
| 742 | |
| 743 // If no resource-specific content settings are defined, the setting should be | |
| 744 // DEFAULT. | |
| 745 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | |
| 746 host_content_settings_map->GetContentSetting( | |
| 747 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | |
| 748 | |
| 749 host_content_settings_map->SetContentSetting( | |
| 750 pattern, | |
| 751 ContentSettingsPattern::Wildcard(), | |
| 752 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 753 resource1, | |
| 754 CONTENT_SETTING_BLOCK); | |
| 755 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 756 host_content_settings_map->GetContentSetting( | |
| 757 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | |
| 758 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | |
| 759 host_content_settings_map->GetContentSetting( | |
| 760 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); | |
| 761 } | |
| 762 | |
| 763 TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) { | |
| 764 // This feature is currently behind a flag. | |
| 765 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
| 766 base::AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
| 767 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | |
| 768 | |
| 769 TestingProfile profile; | |
| 770 scoped_ptr<Value> value(base::JSONReader::Read( | |
| 771 "{\"[*.]example.com,*\":{\"per_plugin\":{\"someplugin\":2}}}")); | |
| 772 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); | |
| 773 HostContentSettingsMap* host_content_settings_map = | |
| 774 profile.GetHostContentSettingsMap(); | |
| 775 | |
| 776 GURL host("http://example.com/"); | |
| 777 ContentSettingsPattern item_pattern = | |
| 778 ContentSettingsPattern::FromString("[*.]example.com"); | |
| 779 ContentSettingsPattern top_level_frame_pattern = | |
| 780 ContentSettingsPattern::Wildcard(); | |
| 781 std::string resource1("someplugin"); | |
| 782 std::string resource2("otherplugin"); | |
| 783 | |
| 784 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 785 host_content_settings_map->GetContentSetting( | |
| 786 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | |
| 787 | |
| 788 host_content_settings_map->SetContentSetting( | |
| 789 item_pattern, | |
| 790 top_level_frame_pattern, | |
| 791 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 792 resource1, | |
| 793 CONTENT_SETTING_DEFAULT); | |
| 794 | |
| 795 const DictionaryValue* content_setting_prefs = | |
| 796 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | |
| 797 std::string prefs_as_json; | |
| 798 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); | |
| 799 EXPECT_EQ("{}", prefs_as_json); | |
| 800 | |
| 801 host_content_settings_map->SetContentSetting( | |
| 802 item_pattern, | |
| 803 top_level_frame_pattern, | |
| 804 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 805 resource2, | |
| 806 CONTENT_SETTING_BLOCK); | |
| 807 | |
| 808 content_setting_prefs = | |
| 809 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | |
| 810 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); | |
| 811 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}", | |
| 812 prefs_as_json); | |
| 813 } | |
| 814 | |
| 815 // If a default-content-setting is managed, the managed value should be used | 718 // If a default-content-setting is managed, the managed value should be used |
| 816 // instead of the default value. | 719 // instead of the default value. |
| 817 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { | 720 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { |
| 818 TestingProfile profile; | 721 TestingProfile profile; |
| 819 HostContentSettingsMap* host_content_settings_map = | 722 HostContentSettingsMap* host_content_settings_map = |
| 820 profile.GetHostContentSettingsMap(); | 723 profile.GetHostContentSettingsMap(); |
| 821 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 724 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
| 822 | 725 |
| 823 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 726 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 824 host_content_settings_map->GetDefaultContentSetting( | 727 host_content_settings_map->GetDefaultContentSetting( |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 GURL("http://other.com"), | 975 GURL("http://other.com"), |
| 1073 CONTENT_SETTINGS_TYPE_COOKIES, | 976 CONTENT_SETTINGS_TYPE_COOKIES, |
| 1074 std::string())); | 977 std::string())); |
| 1075 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | 978 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, |
| 1076 host_content_settings_map->GetContentSetting( | 979 host_content_settings_map->GetContentSetting( |
| 1077 GURL("http://third.com"), | 980 GURL("http://third.com"), |
| 1078 GURL("http://third.com"), | 981 GURL("http://third.com"), |
| 1079 CONTENT_SETTINGS_TYPE_COOKIES, | 982 CONTENT_SETTINGS_TYPE_COOKIES, |
| 1080 std::string())); | 983 std::string())); |
| 1081 } | 984 } |
| OLD | NEW |