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