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

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

Issue 1754073002: Migrate old settings for ContentSettingTypes with wildcard as secondary_pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoping_set_content_setting
Patch Set: use string 'preference' Created 4 years, 8 months 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
« no previous file with comments | « no previous file | chrome/browser/ssl/chrome_ssl_host_state_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/chrome_ssl_host_state_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698