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 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1155 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1156 host_content_settings_map->GetContentSetting( | 1156 host_content_settings_map->GetContentSetting( |
1157 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1157 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
1158 host_content_settings_map->SetContentSetting( | 1158 host_content_settings_map->SetContentSetting( |
1159 pattern, | 1159 pattern, |
1160 ContentSettingsPattern::Wildcard(), | 1160 ContentSettingsPattern::Wildcard(), |
1161 CONTENT_SETTINGS_TYPE_IMAGES, | 1161 CONTENT_SETTINGS_TYPE_IMAGES, |
1162 std::string(), | 1162 std::string(), |
1163 CONTENT_SETTING_DEFAULT); | 1163 CONTENT_SETTING_DEFAULT); |
1164 } | 1164 } |
| 1165 |
| 1166 TEST_F(HostContentSettingsMapTest, GuestProfile) { |
| 1167 TestingProfile profile; |
| 1168 profile.SetGuestSession(true); |
| 1169 HostContentSettingsMap* host_content_settings_map = |
| 1170 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1171 |
| 1172 GURL host("http://example.com/"); |
| 1173 ContentSettingsPattern pattern = |
| 1174 ContentSettingsPattern::FromString("[*.]example.com"); |
| 1175 |
| 1176 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1177 host_content_settings_map->GetContentSetting( |
| 1178 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1179 |
| 1180 // Changing content settings should not result in any prefs being stored |
| 1181 // however the value should be set in memory. |
| 1182 host_content_settings_map->SetContentSetting( |
| 1183 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES, |
| 1184 std::string(), CONTENT_SETTING_BLOCK); |
| 1185 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1186 host_content_settings_map->GetContentSetting( |
| 1187 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1188 |
| 1189 const base::DictionaryValue* all_settings_dictionary = |
| 1190 profile.GetPrefs()->GetDictionary( |
| 1191 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 1192 EXPECT_TRUE(all_settings_dictionary->empty()); |
| 1193 } |
| 1194 |
| 1195 // Default settings should not be modifiable for the guest profile (there is no |
| 1196 // UI to do this). |
| 1197 TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { |
| 1198 TestingProfile profile; |
| 1199 profile.SetGuestSession(true); |
| 1200 HostContentSettingsMap* host_content_settings_map = |
| 1201 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1202 |
| 1203 GURL host("http://example.com/"); |
| 1204 |
| 1205 // There are no custom rules, so this should be the default. |
| 1206 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1207 host_content_settings_map->GetContentSetting( |
| 1208 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1209 |
| 1210 host_content_settings_map->SetDefaultContentSetting( |
| 1211 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 1212 |
| 1213 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1214 host_content_settings_map->GetContentSetting( |
| 1215 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1216 } |
| 1217 |
| 1218 // We used to incorrectly store content settings in prefs for the guest profile. |
| 1219 // We need to ensure these get deleted appropriately. |
| 1220 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) { |
| 1221 TestingProfile profile; |
| 1222 profile.SetGuestSession(true); |
| 1223 |
| 1224 // Set a pref manually in the guest profile. |
| 1225 scoped_ptr<base::Value> value = |
| 1226 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); |
| 1227 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); |
| 1228 |
| 1229 // Test that during construction all the prefs get cleared. |
| 1230 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1231 |
| 1232 const base::DictionaryValue* all_settings_dictionary = |
| 1233 profile.GetPrefs()->GetDictionary( |
| 1234 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 1235 EXPECT_TRUE(all_settings_dictionary->empty()); |
| 1236 } |
OLD | NEW |