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 ContentSettingsPattern pattern = | |
msramek
2016/01/20 11:01:46
nit: pattern is unused
raymes
2016/01/20 22:55:42
Done.
| |
1205 ContentSettingsPattern::FromString("[*.]example.com"); | |
1206 | |
1207 // There are no custom rules, so this should be the default. | |
1208 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1209 host_content_settings_map->GetContentSetting( | |
1210 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | |
1211 | |
1212 host_content_settings_map->SetDefaultContentSetting( | |
1213 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | |
1214 | |
1215 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1216 host_content_settings_map->GetContentSetting( | |
1217 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | |
1218 } | |
1219 | |
1220 // We used to incorrectly store content settings in prefs for the guest profile. | |
1221 // We need to ensure these get deleted appropriately. | |
1222 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) { | |
1223 TestingProfile profile; | |
1224 profile.SetGuestSession(true); | |
1225 | |
1226 // Set a pref manually in the guest profile. | |
1227 scoped_ptr<base::Value> value = | |
1228 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); | |
1229 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); | |
1230 | |
1231 // Test that during construction all the prefs get cleared. | |
1232 HostContentSettingsMapFactory::GetForProfile(&profile); | |
1233 | |
1234 const base::DictionaryValue* all_settings_dictionary = | |
1235 profile.GetPrefs()->GetDictionary( | |
1236 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | |
1237 EXPECT_TRUE(all_settings_dictionary->empty()); | |
1238 } | |
OLD | NEW |