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

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: rebase Created 4 years, 9 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
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 EXPECT_EQ(
1155 CONTENT_SETTING_ASK,
1156 host_content_settings_map->GetContentSetting(
1157 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
1158 host_content_settings_map->SetContentSettingDefaultScope(
1159 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
1160 CONTENT_SETTING_ALLOW);
1161 host_content_settings_map->SetContentSetting(
1162 pattern, pattern, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
1163 CONTENT_SETTING_BLOCK);
1164 // Because of the old formatted setting entry which has two same patterns,
1165 // SetContentSetting() to (host, GURL()) will be ignored.
1166 host_content_settings_map->SetContentSettingDefaultScope(
1167 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
1168 CONTENT_SETTING_ASK);
1169 EXPECT_EQ(
1170 CONTENT_SETTING_BLOCK,
1171 host_content_settings_map->GetContentSetting(
1172 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
raymes 2016/03/07 01:47:55 Hey Liu, I think maybe we should just test the cas
1173
1174 ContentSettingsForOneType host_settings;
1175 host_content_settings_map->GetSettingsForOneType(
1176 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), &host_settings);
1177 // |host_settings| contains the default setting and two custom settings.
1178 EXPECT_EQ(3U, host_settings.size());
raymes 2016/03/07 01:47:55 I'm a bit confused about why there are 3 here? Sho
lshang 2016/03/23 13:58:36 Yeah, SetContentSettingDefaultScope() twice change
1179
1180 host_content_settings_map->MigrateOldSettings();
1181
1182 host_content_settings_map->GetSettingsForOneType(
1183 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), &host_settings);
1184
1185 // MigrateOldSettings() removed setting entry with the two same patterns.
1186 EXPECT_EQ(2U, host_settings.size());
1187
1188 EXPECT_EQ(
1189 CONTENT_SETTING_BLOCK,
1190 host_content_settings_map->GetContentSetting(
1191 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
1192
1193 // After migrating old settings, changes to the setting works.
1194 host_content_settings_map->SetContentSettingDefaultScope(
1195 host, GURL(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
1196 CONTENT_SETTING_ASK);
1197 EXPECT_EQ(
1198 CONTENT_SETTING_ASK,
1199 host_content_settings_map->GetContentSetting(
1200 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
1201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698