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 "chrome/browser/content_settings/content_settings_mock_observer.h" | 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); | 1134 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); |
1135 | 1135 |
1136 // Test that during construction all the prefs get cleared. | 1136 // Test that during construction all the prefs get cleared. |
1137 HostContentSettingsMapFactory::GetForProfile(&profile); | 1137 HostContentSettingsMapFactory::GetForProfile(&profile); |
1138 | 1138 |
1139 const base::DictionaryValue* all_settings_dictionary = | 1139 const base::DictionaryValue* all_settings_dictionary = |
1140 profile.GetPrefs()->GetDictionary( | 1140 profile.GetPrefs()->GetDictionary( |
1141 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | 1141 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); |
1142 EXPECT_TRUE(all_settings_dictionary->empty()); | 1142 EXPECT_TRUE(all_settings_dictionary->empty()); |
1143 } | 1143 } |
| 1144 |
| 1145 TEST_F(HostContentSettingsMapTest, MigrateOldSettings) { |
| 1146 TestingProfile profile; |
| 1147 HostContentSettingsMap* host_content_settings_map = |
| 1148 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1149 |
| 1150 // Set old formatted settings. |
| 1151 GURL host("http://example.com/"); |
| 1152 ContentSettingsPattern pattern = |
| 1153 ContentSettingsPattern::FromURLNoWildcard(host); |
| 1154 |
| 1155 // Default setting is BLOCK. |
| 1156 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1157 host_content_settings_map->GetContentSetting( |
| 1158 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 1159 |
| 1160 host_content_settings_map->SetContentSetting( |
| 1161 pattern, pattern, CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
| 1162 CONTENT_SETTING_ALLOW); |
| 1163 // Because of the old formatted setting entry which has two same patterns, |
| 1164 // SetContentSetting() to (host, GURL()) will be ignored. |
| 1165 host_content_settings_map->SetContentSettingDefaultScope( |
| 1166 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
| 1167 CONTENT_SETTING_BLOCK); |
| 1168 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1169 host_content_settings_map->GetContentSetting( |
| 1170 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 1171 |
| 1172 host_content_settings_map->MigrateOldSettings(); |
| 1173 |
| 1174 ContentSettingsForOneType settings; |
| 1175 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_KEYGEN, |
| 1176 std::string(), &settings); |
| 1177 for (const ContentSettingPatternSource& setting_entry : settings) { |
| 1178 EXPECT_EQ(setting_entry.secondary_pattern, |
| 1179 ContentSettingsPattern::Wildcard()); |
| 1180 } |
| 1181 |
| 1182 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1183 host_content_settings_map->GetContentSetting( |
| 1184 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 1185 |
| 1186 // After migrating old settings, changes to the setting works. |
| 1187 host_content_settings_map->SetContentSettingDefaultScope( |
| 1188 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
| 1189 CONTENT_SETTING_BLOCK); |
| 1190 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1191 host_content_settings_map->GetContentSetting( |
| 1192 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 1193 } |
OLD | NEW |