Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
82 NOTREACHED(); 82 NOTREACHED();
83 } 83 }
84 } 84 }
85 85
86 void ClearPolicyDefault() { 86 void ClearPolicyDefault() {
87 prefs_->RemoveManagedPref(policy_default_setting_); 87 prefs_->RemoveManagedPref(policy_default_setting_);
88 } 88 }
89 89
90 void SetPolicyDefault(ContentSetting setting) { 90 void SetPolicyDefault(ContentSetting setting) {
91 prefs_->SetManagedPref(policy_default_setting_, 91 prefs_->SetManagedPref(policy_default_setting_,
92 new base::FundamentalValue(setting)); 92 new base::Value(setting));
93 } 93 }
94 94
95 void AddUserException(std::string exception, 95 void AddUserException(std::string exception,
96 ContentSetting content_settings) { 96 ContentSetting content_settings) {
97 ContentSettingsPattern pattern = 97 ContentSettingsPattern pattern =
98 ContentSettingsPattern::FromString(exception); 98 ContentSettingsPattern::FromString(exception);
99 host_content_settings_map_->SetContentSettingCustomScope( 99 host_content_settings_map_->SetContentSettingCustomScope(
100 pattern, pattern, content_type_, std::string(), content_settings); 100 pattern, pattern, content_type_, std::string(), content_settings);
101 } 101 }
102 102
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 HostContentSettingsMapFactory::GetForProfile(&profile); 1006 HostContentSettingsMapFactory::GetForProfile(&profile);
1007 sync_preferences::TestingPrefServiceSyncable* prefs = 1007 sync_preferences::TestingPrefServiceSyncable* prefs =
1008 profile.GetTestingPrefService(); 1008 profile.GetTestingPrefService();
1009 1009
1010 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1010 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1011 host_content_settings_map->GetDefaultContentSetting( 1011 host_content_settings_map->GetDefaultContentSetting(
1012 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1012 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1013 1013
1014 // Set managed-default-content-setting through the coresponding preferences. 1014 // Set managed-default-content-setting through the coresponding preferences.
1015 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 1015 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1016 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 1016 new base::Value(CONTENT_SETTING_BLOCK));
1017 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1017 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1018 host_content_settings_map->GetDefaultContentSetting( 1018 host_content_settings_map->GetDefaultContentSetting(
1019 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1019 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1020 1020
1021 // Remove managed-default-content-settings-preferences. 1021 // Remove managed-default-content-settings-preferences.
1022 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); 1022 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
1023 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1023 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1024 host_content_settings_map->GetDefaultContentSetting( 1024 host_content_settings_map->GetDefaultContentSetting(
1025 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1025 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1026 1026
1027 #if defined(ENABLE_PLUGINS) 1027 #if defined(ENABLE_PLUGINS)
1028 // Set preference to manage the default-content-setting for Plugins. 1028 // Set preference to manage the default-content-setting for Plugins.
1029 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 1029 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
1030 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 1030 new base::Value(CONTENT_SETTING_BLOCK));
1031 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1031 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1032 host_content_settings_map->GetDefaultContentSetting( 1032 host_content_settings_map->GetDefaultContentSetting(
1033 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1033 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
1034 1034
1035 // Remove the preference to manage the default-content-setting for Plugins. 1035 // Remove the preference to manage the default-content-setting for Plugins.
1036 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 1036 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
1037 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 1037 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
1038 host_content_settings_map->GetDefaultContentSetting( 1038 host_content_settings_map->GetDefaultContentSetting(
1039 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1039 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
1040 #endif 1040 #endif
1041 1041
1042 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1042 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1043 host_content_settings_map->GetDefaultContentSetting( 1043 host_content_settings_map->GetDefaultContentSetting(
1044 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 1044 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1045 1045
1046 // Set managed-default content setting through the coresponding preferences. 1046 // Set managed-default content setting through the coresponding preferences.
1047 prefs->SetManagedPref(prefs::kManagedDefaultKeygenSetting, 1047 prefs->SetManagedPref(prefs::kManagedDefaultKeygenSetting,
1048 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1048 new base::Value(CONTENT_SETTING_ALLOW));
1049 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1049 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1050 host_content_settings_map->GetDefaultContentSetting( 1050 host_content_settings_map->GetDefaultContentSetting(
1051 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 1051 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1052 1052
1053 // Remove managed-default content settings preferences. 1053 // Remove managed-default content settings preferences.
1054 prefs->RemoveManagedPref(prefs::kManagedDefaultKeygenSetting); 1054 prefs->RemoveManagedPref(prefs::kManagedDefaultKeygenSetting);
1055 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1055 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1056 host_content_settings_map->GetDefaultContentSetting( 1056 host_content_settings_map->GetDefaultContentSetting(
1057 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 1057 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1058 } 1058 }
(...skipping 15 matching lines...) Expand all
1074 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1074 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1075 host_content_settings_map->GetDefaultContentSetting( 1075 host_content_settings_map->GetDefaultContentSetting(
1076 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1076 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1077 1077
1078 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1078 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1079 host_content_settings_map->GetContentSetting( 1079 host_content_settings_map->GetContentSetting(
1080 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1080 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1081 1081
1082 // Set managed-default-content-setting for content-settings-type JavaScript. 1082 // Set managed-default-content-setting for content-settings-type JavaScript.
1083 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 1083 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1084 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1084 new base::Value(CONTENT_SETTING_ALLOW));
1085 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1085 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1086 host_content_settings_map->GetContentSetting( 1086 host_content_settings_map->GetContentSetting(
1087 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1087 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1088 } 1088 }
1089 1089
1090 // Managed default content setting should have higher priority 1090 // Managed default content setting should have higher priority
1091 // than user defined patterns. 1091 // than user defined patterns.
1092 TEST_F(HostContentSettingsMapTest, 1092 TEST_F(HostContentSettingsMapTest,
1093 ManagedDefaultContentSettingIgnoreUserPattern) { 1093 ManagedDefaultContentSettingIgnoreUserPattern) {
1094 TestingProfile profile; 1094 TestingProfile profile;
(...skipping 16 matching lines...) Expand all
1111 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1111 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1112 host_content_settings_map->GetDefaultContentSetting( 1112 host_content_settings_map->GetDefaultContentSetting(
1113 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 1113 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
1114 1114
1115 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1115 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1116 host_content_settings_map->GetContentSetting( 1116 host_content_settings_map->GetContentSetting(
1117 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1117 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1118 1118
1119 // Set managed-default-content-settings-preferences. 1119 // Set managed-default-content-settings-preferences.
1120 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 1120 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
1121 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 1121 new base::Value(CONTENT_SETTING_BLOCK));
1122 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1122 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1123 host_content_settings_map->GetContentSetting( 1123 host_content_settings_map->GetContentSetting(
1124 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1124 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1125 1125
1126 // Remove managed-default-content-settings-preferences. 1126 // Remove managed-default-content-settings-preferences.
1127 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); 1127 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
1128 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1128 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1129 host_content_settings_map->GetContentSetting( 1129 host_content_settings_map->GetContentSetting(
1130 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 1130 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
1131 } 1131 }
1132 1132
1133 // If a default-content-setting is set to managed setting, the user defined 1133 // If a default-content-setting is set to managed setting, the user defined
1134 // setting should be preserved. 1134 // setting should be preserved.
1135 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { 1135 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
1136 TestingProfile profile; 1136 TestingProfile profile;
1137 HostContentSettingsMap* host_content_settings_map = 1137 HostContentSettingsMap* host_content_settings_map =
1138 HostContentSettingsMapFactory::GetForProfile(&profile); 1138 HostContentSettingsMapFactory::GetForProfile(&profile);
1139 sync_preferences::TestingPrefServiceSyncable* prefs = 1139 sync_preferences::TestingPrefServiceSyncable* prefs =
1140 profile.GetTestingPrefService(); 1140 profile.GetTestingPrefService();
1141 1141
1142 // Set user defined default-content-setting for Cookies. 1142 // Set user defined default-content-setting for Cookies.
1143 host_content_settings_map->SetDefaultContentSetting( 1143 host_content_settings_map->SetDefaultContentSetting(
1144 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 1144 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1145 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1145 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1146 host_content_settings_map->GetDefaultContentSetting( 1146 host_content_settings_map->GetDefaultContentSetting(
1147 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1147 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1148 1148
1149 // Set preference to manage the default-content-setting for Cookies. 1149 // Set preference to manage the default-content-setting for Cookies.
1150 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, 1150 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
1151 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1151 new base::Value(CONTENT_SETTING_ALLOW));
1152 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1152 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1153 host_content_settings_map->GetDefaultContentSetting( 1153 host_content_settings_map->GetDefaultContentSetting(
1154 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1154 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1155 1155
1156 // Remove the preference to manage the default-content-setting for Cookies. 1156 // Remove the preference to manage the default-content-setting for Cookies.
1157 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); 1157 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
1158 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1158 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1159 host_content_settings_map->GetDefaultContentSetting( 1159 host_content_settings_map->GetDefaultContentSetting(
1160 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1160 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1161 } 1161 }
1162 1162
1163 // If a setting for a default-content-setting-type is set while the type is 1163 // If a setting for a default-content-setting-type is set while the type is
1164 // managed, then the new setting should be preserved and used after the 1164 // managed, then the new setting should be preserved and used after the
1165 // default-content-setting-type is not managed anymore. 1165 // default-content-setting-type is not managed anymore.
1166 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { 1166 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
1167 TestingProfile profile; 1167 TestingProfile profile;
1168 HostContentSettingsMap* host_content_settings_map = 1168 HostContentSettingsMap* host_content_settings_map =
1169 HostContentSettingsMapFactory::GetForProfile(&profile); 1169 HostContentSettingsMapFactory::GetForProfile(&profile);
1170 sync_preferences::TestingPrefServiceSyncable* prefs = 1170 sync_preferences::TestingPrefServiceSyncable* prefs =
1171 profile.GetTestingPrefService(); 1171 profile.GetTestingPrefService();
1172 1172
1173 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, 1173 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
1174 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1174 new base::Value(CONTENT_SETTING_ALLOW));
1175 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1175 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1176 host_content_settings_map->GetDefaultContentSetting( 1176 host_content_settings_map->GetDefaultContentSetting(
1177 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1177 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1178 1178
1179 host_content_settings_map->SetDefaultContentSetting( 1179 host_content_settings_map->SetDefaultContentSetting(
1180 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 1180 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1181 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1181 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1182 host_content_settings_map->GetDefaultContentSetting( 1182 host_content_settings_map->GetDefaultContentSetting(
1183 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 1183 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1184 1184
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( 1734 host_content_settings_map->ClearSettingsForOneTypeWithPredicate(
1735 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 1735 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
1736 base::Bind(&MatchPrimaryPattern, http_pattern)); 1736 base::Bind(&MatchPrimaryPattern, http_pattern));
1737 // Verify we only have one, and it's url1. 1737 // Verify we only have one, and it's url1.
1738 host_content_settings_map->GetSettingsForOneType( 1738 host_content_settings_map->GetSettingsForOneType(
1739 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); 1739 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
1740 EXPECT_EQ(1u, host_settings.size()); 1740 EXPECT_EQ(1u, host_settings.size());
1741 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 1741 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
1742 host_settings[0].primary_pattern); 1742 host_settings[0].primary_pattern);
1743 } 1743 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698