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

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

Issue 1605453003: Ensure content settings aren't persisted in the guest profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
msramek 2016/01/19 13:35:07 Following the comment in host_content_settings_map
raymes 2016/01/19 23:31:39 Agreed. This seems like a reasonable solution for
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 // We used to incorrectly store content settings in prefs for the guest profile.
1196 // We need to ensure these get deleted appropriately.
1197 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) {
1198 TestingProfile profile;
1199 profile.SetGuestSession(true);
1200
1201 // Set a pref manually in the guest profile.
1202 scoped_ptr<base::Value> value =
1203 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}");
1204 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value);
1205
1206 // Test that during construction all the prefs get cleared.
1207 HostContentSettingsMapFactory::GetForProfile(&profile);
1208
1209 const base::DictionaryValue* all_settings_dictionary =
1210 profile.GetPrefs()->GetDictionary(
1211 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES));
1212 EXPECT_TRUE(all_settings_dictionary->empty());
1213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698