| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Add support as needed. | 82 // Add support as needed. |
| 83 NOTREACHED(); | 83 NOTREACHED(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ClearPolicyDefault() { | 87 void ClearPolicyDefault() { |
| 88 prefs_->RemoveManagedPref(policy_default_setting_); | 88 prefs_->RemoveManagedPref(policy_default_setting_); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SetPolicyDefault(ContentSetting setting) { | 91 void SetPolicyDefault(ContentSetting setting) { |
| 92 prefs_->SetManagedPref(policy_default_setting_, | 92 prefs_->SetManagedPref(policy_default_setting_, new base::Value(setting)); |
| 93 new base::FundamentalValue(setting)); | |
| 94 } | 93 } |
| 95 | 94 |
| 96 void AddUserException(std::string exception, | 95 void AddUserException(std::string exception, |
| 97 ContentSetting content_settings) { | 96 ContentSetting content_settings) { |
| 98 ContentSettingsPattern pattern = | 97 ContentSettingsPattern pattern = |
| 99 ContentSettingsPattern::FromString(exception); | 98 ContentSettingsPattern::FromString(exception); |
| 100 host_content_settings_map_->SetContentSettingCustomScope( | 99 host_content_settings_map_->SetContentSettingCustomScope( |
| 101 pattern, pattern, content_type_, std::string(), content_settings); | 100 pattern, pattern, content_type_, std::string(), content_settings); |
| 102 } | 101 } |
| 103 | 102 |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 HostContentSettingsMapFactory::GetForProfile(&profile); | 1036 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1038 sync_preferences::TestingPrefServiceSyncable* prefs = | 1037 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 1039 profile.GetTestingPrefService(); | 1038 profile.GetTestingPrefService(); |
| 1040 | 1039 |
| 1041 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1040 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1042 host_content_settings_map->GetDefaultContentSetting( | 1041 host_content_settings_map->GetDefaultContentSetting( |
| 1043 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 1042 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| 1044 | 1043 |
| 1045 // Set managed-default-content-setting through the coresponding preferences. | 1044 // Set managed-default-content-setting through the coresponding preferences. |
| 1046 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 1045 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
| 1047 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 1046 new base::Value(CONTENT_SETTING_BLOCK)); |
| 1048 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1047 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1049 host_content_settings_map->GetDefaultContentSetting( | 1048 host_content_settings_map->GetDefaultContentSetting( |
| 1050 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 1049 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| 1051 | 1050 |
| 1052 // Remove managed-default-content-settings-preferences. | 1051 // Remove managed-default-content-settings-preferences. |
| 1053 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); | 1052 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); |
| 1054 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1053 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1055 host_content_settings_map->GetDefaultContentSetting( | 1054 host_content_settings_map->GetDefaultContentSetting( |
| 1056 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 1055 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| 1057 | 1056 |
| 1058 #if BUILDFLAG(ENABLE_PLUGINS) | 1057 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1059 // Set preference to manage the default-content-setting for Plugins. | 1058 // Set preference to manage the default-content-setting for Plugins. |
| 1060 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, | 1059 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, |
| 1061 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 1060 new base::Value(CONTENT_SETTING_BLOCK)); |
| 1062 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1061 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1063 host_content_settings_map->GetDefaultContentSetting( | 1062 host_content_settings_map->GetDefaultContentSetting( |
| 1064 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1063 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
| 1065 | 1064 |
| 1066 // Remove the preference to manage the default-content-setting for Plugins. | 1065 // Remove the preference to manage the default-content-setting for Plugins. |
| 1067 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 1066 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
| 1068 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, | 1067 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, |
| 1069 host_content_settings_map->GetDefaultContentSetting( | 1068 host_content_settings_map->GetDefaultContentSetting( |
| 1070 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1069 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
| 1071 #endif | 1070 #endif |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1088 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1087 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1089 host_content_settings_map->GetDefaultContentSetting( | 1088 host_content_settings_map->GetDefaultContentSetting( |
| 1090 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 1089 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| 1091 | 1090 |
| 1092 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1091 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1093 host_content_settings_map->GetContentSetting( | 1092 host_content_settings_map->GetContentSetting( |
| 1094 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 1093 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1095 | 1094 |
| 1096 // Set managed-default-content-setting for content-settings-type JavaScript. | 1095 // Set managed-default-content-setting for content-settings-type JavaScript. |
| 1097 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 1096 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
| 1098 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 1097 new base::Value(CONTENT_SETTING_ALLOW)); |
| 1099 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1098 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1100 host_content_settings_map->GetContentSetting( | 1099 host_content_settings_map->GetContentSetting( |
| 1101 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 1100 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1102 } | 1101 } |
| 1103 | 1102 |
| 1104 // Managed default content setting should have higher priority | 1103 // Managed default content setting should have higher priority |
| 1105 // than user defined patterns. | 1104 // than user defined patterns. |
| 1106 TEST_F(HostContentSettingsMapTest, | 1105 TEST_F(HostContentSettingsMapTest, |
| 1107 ManagedDefaultContentSettingIgnoreUserPattern) { | 1106 ManagedDefaultContentSettingIgnoreUserPattern) { |
| 1108 TestingProfile profile; | 1107 TestingProfile profile; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1125 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1124 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1126 host_content_settings_map->GetDefaultContentSetting( | 1125 host_content_settings_map->GetDefaultContentSetting( |
| 1127 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 1126 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| 1128 | 1127 |
| 1129 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1128 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1130 host_content_settings_map->GetContentSetting( | 1129 host_content_settings_map->GetContentSetting( |
| 1131 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 1130 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1132 | 1131 |
| 1133 // Set managed-default-content-settings-preferences. | 1132 // Set managed-default-content-settings-preferences. |
| 1134 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, | 1133 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, |
| 1135 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 1134 new base::Value(CONTENT_SETTING_BLOCK)); |
| 1136 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1135 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1137 host_content_settings_map->GetContentSetting( | 1136 host_content_settings_map->GetContentSetting( |
| 1138 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 1137 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1139 | 1138 |
| 1140 // Remove managed-default-content-settings-preferences. | 1139 // Remove managed-default-content-settings-preferences. |
| 1141 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); | 1140 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); |
| 1142 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1141 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1143 host_content_settings_map->GetContentSetting( | 1142 host_content_settings_map->GetContentSetting( |
| 1144 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 1143 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1145 } | 1144 } |
| 1146 | 1145 |
| 1147 // If a default-content-setting is set to managed setting, the user defined | 1146 // If a default-content-setting is set to managed setting, the user defined |
| 1148 // setting should be preserved. | 1147 // setting should be preserved. |
| 1149 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { | 1148 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { |
| 1150 TestingProfile profile; | 1149 TestingProfile profile; |
| 1151 HostContentSettingsMap* host_content_settings_map = | 1150 HostContentSettingsMap* host_content_settings_map = |
| 1152 HostContentSettingsMapFactory::GetForProfile(&profile); | 1151 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1153 sync_preferences::TestingPrefServiceSyncable* prefs = | 1152 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 1154 profile.GetTestingPrefService(); | 1153 profile.GetTestingPrefService(); |
| 1155 | 1154 |
| 1156 // Set user defined default-content-setting for Cookies. | 1155 // Set user defined default-content-setting for Cookies. |
| 1157 host_content_settings_map->SetDefaultContentSetting( | 1156 host_content_settings_map->SetDefaultContentSetting( |
| 1158 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1157 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1159 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1158 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1160 host_content_settings_map->GetDefaultContentSetting( | 1159 host_content_settings_map->GetDefaultContentSetting( |
| 1161 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 1160 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
| 1162 | 1161 |
| 1163 // Set preference to manage the default-content-setting for Cookies. | 1162 // Set preference to manage the default-content-setting for Cookies. |
| 1164 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, | 1163 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
| 1165 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 1164 new base::Value(CONTENT_SETTING_ALLOW)); |
| 1166 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1165 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1167 host_content_settings_map->GetDefaultContentSetting( | 1166 host_content_settings_map->GetDefaultContentSetting( |
| 1168 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 1167 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
| 1169 | 1168 |
| 1170 // Remove the preference to manage the default-content-setting for Cookies. | 1169 // Remove the preference to manage the default-content-setting for Cookies. |
| 1171 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); | 1170 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
| 1172 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1171 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1173 host_content_settings_map->GetDefaultContentSetting( | 1172 host_content_settings_map->GetDefaultContentSetting( |
| 1174 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 1173 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
| 1175 } | 1174 } |
| 1176 | 1175 |
| 1177 // If a setting for a default-content-setting-type is set while the type is | 1176 // If a setting for a default-content-setting-type is set while the type is |
| 1178 // managed, then the new setting should be preserved and used after the | 1177 // managed, then the new setting should be preserved and used after the |
| 1179 // default-content-setting-type is not managed anymore. | 1178 // default-content-setting-type is not managed anymore. |
| 1180 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { | 1179 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { |
| 1181 TestingProfile profile; | 1180 TestingProfile profile; |
| 1182 HostContentSettingsMap* host_content_settings_map = | 1181 HostContentSettingsMap* host_content_settings_map = |
| 1183 HostContentSettingsMapFactory::GetForProfile(&profile); | 1182 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1184 sync_preferences::TestingPrefServiceSyncable* prefs = | 1183 sync_preferences::TestingPrefServiceSyncable* prefs = |
| 1185 profile.GetTestingPrefService(); | 1184 profile.GetTestingPrefService(); |
| 1186 | 1185 |
| 1187 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, | 1186 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
| 1188 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 1187 new base::Value(CONTENT_SETTING_ALLOW)); |
| 1189 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1188 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1190 host_content_settings_map->GetDefaultContentSetting( | 1189 host_content_settings_map->GetDefaultContentSetting( |
| 1191 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 1190 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
| 1192 | 1191 |
| 1193 host_content_settings_map->SetDefaultContentSetting( | 1192 host_content_settings_map->SetDefaultContentSetting( |
| 1194 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1193 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1195 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1194 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1196 host_content_settings_map->GetDefaultContentSetting( | 1195 host_content_settings_map->GetDefaultContentSetting( |
| 1197 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | 1196 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); |
| 1198 | 1197 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 EXPECT_TRUE(map->CanSetNarrowestContentSetting( | 1749 EXPECT_TRUE(map->CanSetNarrowestContentSetting( |
| 1751 valid_url, valid_url, | 1750 valid_url, valid_url, |
| 1752 CONTENT_SETTINGS_TYPE_POPUPS)); | 1751 CONTENT_SETTINGS_TYPE_POPUPS)); |
| 1753 | 1752 |
| 1754 GURL invalid_url("about:blank"); | 1753 GURL invalid_url("about:blank"); |
| 1755 EXPECT_FALSE(map->CanSetNarrowestContentSetting( | 1754 EXPECT_FALSE(map->CanSetNarrowestContentSetting( |
| 1756 invalid_url, invalid_url, | 1755 invalid_url, invalid_url, |
| 1757 CONTENT_SETTINGS_TYPE_POPUPS)); | 1756 CONTENT_SETTINGS_TYPE_POPUPS)); |
| 1758 } | 1757 } |
| 1759 | 1758 |
| OLD | NEW |