| 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.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/content_settings/content_settings_details.h" | 10 #include "chrome/browser/content_settings/content_settings_details.h" |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 scoped_ptr<Value> puny_value(base::JSONReader::Read( | 752 scoped_ptr<Value> puny_value(base::JSONReader::Read( |
| 753 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", false)); | 753 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", false)); |
| 754 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); | 754 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *puny_value); |
| 755 | 755 |
| 756 // Initialize the content map. | 756 // Initialize the content map. |
| 757 profile.GetHostContentSettingsMap(); | 757 profile.GetHostContentSettingsMap(); |
| 758 | 758 |
| 759 const DictionaryValue* content_setting_prefs = | 759 const DictionaryValue* content_setting_prefs = |
| 760 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 760 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 761 std::string prefs_as_json; | 761 std::string prefs_as_json; |
| 762 base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); | 762 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
| 763 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", | 763 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}", |
| 764 prefs_as_json.c_str()); | 764 prefs_as_json.c_str()); |
| 765 } | 765 } |
| 766 | 766 |
| 767 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { | 767 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { |
| 768 // This feature is currently behind a flag. | 768 // This feature is currently behind a flag. |
| 769 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 769 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 770 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 770 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 771 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 771 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 772 | 772 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 host_content_settings_map->SetContentSetting( | 837 host_content_settings_map->SetContentSetting( |
| 838 item_pattern, | 838 item_pattern, |
| 839 top_level_frame_pattern, | 839 top_level_frame_pattern, |
| 840 CONTENT_SETTINGS_TYPE_PLUGINS, | 840 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 841 resource1, | 841 resource1, |
| 842 CONTENT_SETTING_DEFAULT); | 842 CONTENT_SETTING_DEFAULT); |
| 843 | 843 |
| 844 const DictionaryValue* content_setting_prefs = | 844 const DictionaryValue* content_setting_prefs = |
| 845 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 845 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 846 std::string prefs_as_json; | 846 std::string prefs_as_json; |
| 847 base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); | 847 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
| 848 EXPECT_EQ("{}", prefs_as_json); | 848 EXPECT_EQ("{}", prefs_as_json); |
| 849 | 849 |
| 850 host_content_settings_map->SetContentSetting( | 850 host_content_settings_map->SetContentSetting( |
| 851 item_pattern, | 851 item_pattern, |
| 852 top_level_frame_pattern, | 852 top_level_frame_pattern, |
| 853 CONTENT_SETTINGS_TYPE_PLUGINS, | 853 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 854 resource2, | 854 resource2, |
| 855 CONTENT_SETTING_BLOCK); | 855 CONTENT_SETTING_BLOCK); |
| 856 | 856 |
| 857 content_setting_prefs = | 857 content_setting_prefs = |
| 858 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); | 858 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatternPairs); |
| 859 base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); | 859 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); |
| 860 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}", | 860 EXPECT_EQ("{\"[*.]example.com,*\":{\"per_plugin\":{\"otherplugin\":2}}}", |
| 861 prefs_as_json); | 861 prefs_as_json); |
| 862 } | 862 } |
| 863 | 863 |
| 864 // If a default-content-setting is managed, the managed value should be used | 864 // If a default-content-setting is managed, the managed value should be used |
| 865 // instead of the default value. | 865 // instead of the default value. |
| 866 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { | 866 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { |
| 867 TestingProfile profile; | 867 TestingProfile profile; |
| 868 HostContentSettingsMap* host_content_settings_map = | 868 HostContentSettingsMap* host_content_settings_map = |
| 869 profile.GetHostContentSettingsMap(); | 869 profile.GetHostContentSettingsMap(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 CONTENT_SETTINGS_TYPE_IMAGES, | 1051 CONTENT_SETTINGS_TYPE_IMAGES, |
| 1052 std::string(), | 1052 std::string(), |
| 1053 CONTENT_SETTING_BLOCK); | 1053 CONTENT_SETTING_BLOCK); |
| 1054 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1054 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1055 host_content_settings_map->GetContentSetting( | 1055 host_content_settings_map->GetContentSetting( |
| 1056 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 1056 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 1057 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1057 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1058 host_content_settings_map->GetContentSetting( | 1058 host_content_settings_map->GetContentSetting( |
| 1059 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 1059 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 1060 } | 1060 } |
| OLD | NEW |