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

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

Issue 2039803002: Unregister Images, Plugins and Mouselock content settings on android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@only_register_platform_used_contentsettingtypes
Patch Set: nit change in comments Created 4 years, 6 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 // Wrapper to query GetWebsiteSetting(), and only return the source. 92 // Wrapper to query GetWebsiteSetting(), and only return the source.
93 content_settings::SettingSource GetSettingSourceForURL( 93 content_settings::SettingSource GetSettingSourceForURL(
94 const std::string& url_str) { 94 const std::string& url_str) {
95 GURL url(url_str); 95 GURL url(url_str);
96 content_settings::SettingInfo setting_info; 96 content_settings::SettingInfo setting_info;
97 std::unique_ptr<base::Value> result = 97 std::unique_ptr<base::Value> result =
98 host_content_settings_map_->GetWebsiteSetting( 98 host_content_settings_map_->GetWebsiteSetting(
99 url, url, content_type_, std::string(), &setting_info); 99 url, url, content_type_, std::string(), &setting_info);
100 return setting_info.source; 100 return setting_info.source;
101 }; 101 }
102 102
103 private: 103 private:
104 syncable_prefs::TestingPrefServiceSyncable* prefs_; 104 syncable_prefs::TestingPrefServiceSyncable* prefs_;
105 HostContentSettingsMap* host_content_settings_map_; 105 HostContentSettingsMap* host_content_settings_map_;
106 ContentSettingsType content_type_; 106 ContentSettingsType content_type_;
107 const char* policy_default_setting_; 107 const char* policy_default_setting_;
108 108
109 DISALLOW_COPY_AND_ASSIGN(TesterForType); 109 DISALLOW_COPY_AND_ASSIGN(TesterForType);
110 }; 110 };
111 111
112 TEST_F(HostContentSettingsMapTest, DefaultValues) { 112 TEST_F(HostContentSettingsMapTest, DefaultValues) {
113 TestingProfile profile; 113 TestingProfile profile;
114 HostContentSettingsMap* host_content_settings_map = 114 HostContentSettingsMap* host_content_settings_map =
115 HostContentSettingsMapFactory::GetForProfile(&profile); 115 HostContentSettingsMapFactory::GetForProfile(&profile);
116 116
117 // Check setting defaults. 117 // Check setting defaults.
118 EXPECT_EQ(CONTENT_SETTING_ALLOW, 118 EXPECT_EQ(CONTENT_SETTING_ALLOW,
119 host_content_settings_map->GetDefaultContentSetting( 119 host_content_settings_map->GetDefaultContentSetting(
120 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 120 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
121 host_content_settings_map->SetDefaultContentSetting( 121 host_content_settings_map->SetDefaultContentSetting(
122 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 122 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
123 EXPECT_EQ(CONTENT_SETTING_BLOCK, 123 EXPECT_EQ(CONTENT_SETTING_BLOCK,
124 host_content_settings_map->GetDefaultContentSetting( 124 host_content_settings_map->GetDefaultContentSetting(
125 CONTENT_SETTINGS_TYPE_IMAGES, NULL)); 125 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
126 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( 126 EXPECT_EQ(
127 GURL(chrome::kChromeUINewTabURL), 127 CONTENT_SETTING_ALLOW,
128 GURL(chrome::kChromeUINewTabURL), 128 host_content_settings_map->GetContentSetting(
129 CONTENT_SETTINGS_TYPE_IMAGES, 129 GURL(chrome::kChromeUINewTabURL), GURL(chrome::kChromeUINewTabURL),
130 std::string())); 130 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
131 131
132 #if defined(ENABLE_PLUGINS) 132 #if defined(ENABLE_PLUGINS)
133 host_content_settings_map->SetDefaultContentSetting( 133 host_content_settings_map->SetDefaultContentSetting(
134 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); 134 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW);
135 EXPECT_EQ(CONTENT_SETTING_ALLOW, 135 EXPECT_EQ(CONTENT_SETTING_ALLOW,
136 host_content_settings_map->GetDefaultContentSetting( 136 host_content_settings_map->GetDefaultContentSetting(
137 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 137 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
138 host_content_settings_map->SetDefaultContentSetting( 138 host_content_settings_map->SetDefaultContentSetting(
139 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 139 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
140 EXPECT_EQ(CONTENT_SETTING_BLOCK, 140 EXPECT_EQ(CONTENT_SETTING_BLOCK,
(...skipping 18 matching lines...) Expand all
159 159
160 TEST_F(HostContentSettingsMapTest, IndividualSettings) { 160 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
161 TestingProfile profile; 161 TestingProfile profile;
162 HostContentSettingsMap* host_content_settings_map = 162 HostContentSettingsMap* host_content_settings_map =
163 HostContentSettingsMapFactory::GetForProfile(&profile); 163 HostContentSettingsMapFactory::GetForProfile(&profile);
164 164
165 // Check returning individual settings. 165 // Check returning individual settings.
166 GURL host("http://example.com/"); 166 GURL host("http://example.com/");
167 EXPECT_EQ(CONTENT_SETTING_ALLOW, 167 EXPECT_EQ(CONTENT_SETTING_ALLOW,
168 host_content_settings_map->GetContentSetting( 168 host_content_settings_map->GetContentSetting(
169 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 169 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
170 host_content_settings_map->SetContentSettingDefaultScope( 170 host_content_settings_map->SetContentSettingDefaultScope(
171 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 171 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
172 CONTENT_SETTING_DEFAULT); 172 CONTENT_SETTING_DEFAULT);
173 EXPECT_EQ(CONTENT_SETTING_ALLOW, 173 EXPECT_EQ(CONTENT_SETTING_ALLOW,
174 host_content_settings_map->GetContentSetting( 174 host_content_settings_map->GetContentSetting(
175 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 175 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
176 host_content_settings_map->SetContentSettingDefaultScope( 176 host_content_settings_map->SetContentSettingDefaultScope(
177 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 177 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
178 CONTENT_SETTING_BLOCK); 178 CONTENT_SETTING_BLOCK);
179 EXPECT_EQ(CONTENT_SETTING_BLOCK, 179 EXPECT_EQ(CONTENT_SETTING_BLOCK,
180 host_content_settings_map->GetContentSetting( 180 host_content_settings_map->GetContentSetting(
181 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 181 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
182 #if defined(ENABLE_PLUGINS) 182 #if defined(ENABLE_PLUGINS)
183 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 183 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
184 host_content_settings_map->GetContentSetting( 184 host_content_settings_map->GetContentSetting(
185 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 185 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
186 #endif 186 #endif
187 187
188 // Check returning all settings for a host. 188 // Check returning all settings for a host.
189 host_content_settings_map->SetContentSettingDefaultScope( 189 host_content_settings_map->SetContentSettingDefaultScope(
190 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
191 CONTENT_SETTING_DEFAULT);
192 EXPECT_EQ(CONTENT_SETTING_ALLOW,
193 host_content_settings_map->GetContentSetting(
194 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
195 host_content_settings_map->SetContentSettingDefaultScope(
196 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), 190 host, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
197 CONTENT_SETTING_BLOCK); 191 CONTENT_SETTING_BLOCK);
198 EXPECT_EQ(CONTENT_SETTING_BLOCK, 192 EXPECT_EQ(CONTENT_SETTING_BLOCK,
199 host_content_settings_map->GetContentSetting( 193 host_content_settings_map->GetContentSetting(
200 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 194 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
201 #if defined(ENABLE_PLUGINS) 195 #if defined(ENABLE_PLUGINS)
202 host_content_settings_map->SetContentSettingDefaultScope( 196 host_content_settings_map->SetContentSettingDefaultScope(
203 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), 197 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
204 CONTENT_SETTING_ALLOW); 198 CONTENT_SETTING_ALLOW);
205 EXPECT_EQ(CONTENT_SETTING_ALLOW, 199 EXPECT_EQ(CONTENT_SETTING_ALLOW,
206 host_content_settings_map->GetContentSetting( 200 host_content_settings_map->GetContentSetting(
207 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 201 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string()));
208 #endif 202 #endif
209 EXPECT_EQ(CONTENT_SETTING_BLOCK, 203 EXPECT_EQ(CONTENT_SETTING_BLOCK,
210 host_content_settings_map->GetContentSetting( 204 host_content_settings_map->GetContentSetting(
211 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 205 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
212 EXPECT_EQ(CONTENT_SETTING_ASK, 206 EXPECT_EQ(CONTENT_SETTING_ASK,
213 host_content_settings_map->GetContentSetting( 207 host_content_settings_map->GetContentSetting(
214 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 208 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
215 EXPECT_EQ( 209 EXPECT_EQ(
216 CONTENT_SETTING_ASK, 210 CONTENT_SETTING_ASK,
217 host_content_settings_map->GetContentSetting( 211 host_content_settings_map->GetContentSetting(
218 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 212 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
219 EXPECT_EQ(CONTENT_SETTING_ASK, 213 EXPECT_EQ(CONTENT_SETTING_ASK,
220 host_content_settings_map->GetContentSetting( 214 host_content_settings_map->GetContentSetting(
221 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 215 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
222 EXPECT_EQ(CONTENT_SETTING_ASK,
223 host_content_settings_map->GetContentSetting(
224 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
225 216
226 host_content_settings_map->SetContentSettingDefaultScope( 217 host_content_settings_map->SetContentSettingDefaultScope(
227 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), 218 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
228 CONTENT_SETTING_ALLOW); 219 CONTENT_SETTING_ALLOW);
229 EXPECT_EQ(CONTENT_SETTING_ALLOW, 220 EXPECT_EQ(CONTENT_SETTING_ALLOW,
230 host_content_settings_map->GetContentSetting( 221 host_content_settings_map->GetContentSetting(
231 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 222 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
232 223
233 host_content_settings_map->SetContentSettingDefaultScope( 224 host_content_settings_map->SetContentSettingDefaultScope(
234 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), 225 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(),
235 CONTENT_SETTING_BLOCK); 226 CONTENT_SETTING_BLOCK);
236 EXPECT_EQ(CONTENT_SETTING_BLOCK, 227 EXPECT_EQ(CONTENT_SETTING_BLOCK,
237 host_content_settings_map->GetContentSetting( 228 host_content_settings_map->GetContentSetting(
238 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 229 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
239 230
240 // Check returning all hosts for a setting. 231 // Check returning all hosts for a setting.
241 GURL host2("http://example.org/"); 232 GURL host2("http://example.org/");
242 host_content_settings_map->SetContentSettingDefaultScope( 233 host_content_settings_map->SetContentSettingDefaultScope(
243 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 234 host2, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
244 CONTENT_SETTING_BLOCK); 235 CONTENT_SETTING_BLOCK);
245 #if defined(ENABLE_PLUGINS) 236 #if defined(ENABLE_PLUGINS)
246 host_content_settings_map->SetContentSettingDefaultScope( 237 host_content_settings_map->SetContentSettingDefaultScope(
247 host2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), 238 host2, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
248 CONTENT_SETTING_BLOCK); 239 CONTENT_SETTING_BLOCK);
249 #endif 240 #endif
250 ContentSettingsForOneType host_settings; 241 ContentSettingsForOneType host_settings;
251 host_content_settings_map->GetSettingsForOneType( 242 host_content_settings_map->GetSettingsForOneType(
252 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 243 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &host_settings);
253 // |host_settings| contains the default setting and an exception. 244 // |host_settings| contains the default setting and 2 exception.
254 EXPECT_EQ(2U, host_settings.size()); 245 EXPECT_EQ(3U, host_settings.size());
255 #if defined(ENABLE_PLUGINS) 246 #if defined(ENABLE_PLUGINS)
256 host_content_settings_map->GetSettingsForOneType( 247 host_content_settings_map->GetSettingsForOneType(
257 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 248 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
258 // |host_settings| contains the default setting and 2 exceptions. 249 // |host_settings| contains the default setting and 2 exceptions.
259 EXPECT_EQ(3U, host_settings.size()); 250 EXPECT_EQ(3U, host_settings.size());
260 #endif 251 #endif
261 host_content_settings_map->GetSettingsForOneType( 252 host_content_settings_map->GetSettingsForOneType(
262 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 253 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
263 // |host_settings| contains only the default setting. 254 // |host_settings| contains only the default setting.
264 EXPECT_EQ(1U, host_settings.size()); 255 EXPECT_EQ(1U, host_settings.size());
265 } 256 }
266 257
267 TEST_F(HostContentSettingsMapTest, Clear) { 258 TEST_F(HostContentSettingsMapTest, Clear) {
268 TestingProfile profile; 259 TestingProfile profile;
269 HostContentSettingsMap* host_content_settings_map = 260 HostContentSettingsMap* host_content_settings_map =
270 HostContentSettingsMapFactory::GetForProfile(&profile); 261 HostContentSettingsMapFactory::GetForProfile(&profile);
271 262
272 // Check clearing one type. 263 // Check clearing one type.
273 GURL host("http://example.org/"); 264 GURL host("http://example.org/");
274 GURL host2("http://example.net/"); 265 GURL host2("http://example.net/");
275 host_content_settings_map->SetContentSettingDefaultScope( 266 host_content_settings_map->SetContentSettingDefaultScope(
276 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 267 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
277 CONTENT_SETTING_BLOCK); 268 CONTENT_SETTING_BLOCK);
278 host_content_settings_map->SetContentSettingDefaultScope( 269 host_content_settings_map->SetContentSettingDefaultScope(
279 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 270 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
280 CONTENT_SETTING_BLOCK); 271 CONTENT_SETTING_BLOCK);
281 #if defined(ENABLE_PLUGINS) 272 #if defined(ENABLE_PLUGINS)
282 host_content_settings_map->SetContentSettingDefaultScope( 273 host_content_settings_map->SetContentSettingDefaultScope(
283 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), 274 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
284 CONTENT_SETTING_BLOCK); 275 CONTENT_SETTING_BLOCK);
285 #endif 276 #endif
286 host_content_settings_map->SetContentSettingDefaultScope( 277 host_content_settings_map->SetContentSettingDefaultScope(
287 host2, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 278 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
288 CONTENT_SETTING_BLOCK); 279 CONTENT_SETTING_BLOCK);
289 host_content_settings_map->ClearSettingsForOneType( 280 host_content_settings_map->ClearSettingsForOneType(
290 CONTENT_SETTINGS_TYPE_IMAGES); 281 CONTENT_SETTINGS_TYPE_COOKIES);
291 ContentSettingsForOneType host_settings; 282 ContentSettingsForOneType host_settings;
292 host_content_settings_map->GetSettingsForOneType( 283 host_content_settings_map->GetSettingsForOneType(
293 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); 284 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings);
294 // |host_settings| contains only the default setting. 285 // |host_settings| contains only the default setting.
295 EXPECT_EQ(1U, host_settings.size()); 286 EXPECT_EQ(1U, host_settings.size());
296 #if defined(ENABLE_PLUGINS) 287 #if defined(ENABLE_PLUGINS)
297 host_content_settings_map->GetSettingsForOneType( 288 host_content_settings_map->GetSettingsForOneType(
298 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 289 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
299 // |host_settings| contains the default setting and an exception. 290 // |host_settings| contains the default setting and an exception.
300 EXPECT_EQ(2U, host_settings.size()); 291 EXPECT_EQ(2U, host_settings.size());
301 #endif 292 #endif
302 } 293 }
303 294
304 TEST_F(HostContentSettingsMapTest, Patterns) { 295 TEST_F(HostContentSettingsMapTest, Patterns) {
305 TestingProfile profile; 296 TestingProfile profile;
306 HostContentSettingsMap* host_content_settings_map = 297 HostContentSettingsMap* host_content_settings_map =
307 HostContentSettingsMapFactory::GetForProfile(&profile); 298 HostContentSettingsMapFactory::GetForProfile(&profile);
308 299
309 GURL host1("http://example.com/"); 300 GURL host1("http://example.com/");
310 GURL host2("http://www.example.com/"); 301 GURL host2("http://www.example.com/");
311 GURL host3("http://example.org/"); 302 GURL host3("http://example.org/");
312 EXPECT_EQ(CONTENT_SETTING_ALLOW, 303 EXPECT_EQ(CONTENT_SETTING_ALLOW,
313 host_content_settings_map->GetContentSetting( 304 host_content_settings_map->GetContentSetting(
314 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 305 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
315 host_content_settings_map->SetContentSettingDefaultScope( 306 host_content_settings_map->SetContentSettingDefaultScope(
316 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 307 host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
317 CONTENT_SETTING_BLOCK); 308 CONTENT_SETTING_BLOCK);
318 EXPECT_EQ(CONTENT_SETTING_BLOCK, 309 EXPECT_EQ(CONTENT_SETTING_BLOCK,
319 host_content_settings_map->GetContentSetting( 310 host_content_settings_map->GetContentSetting(
320 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 311 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
321 EXPECT_EQ(CONTENT_SETTING_BLOCK, 312 EXPECT_EQ(CONTENT_SETTING_BLOCK,
322 host_content_settings_map->GetContentSetting( 313 host_content_settings_map->GetContentSetting(
323 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 314 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
324 EXPECT_EQ(CONTENT_SETTING_ALLOW, 315 EXPECT_EQ(CONTENT_SETTING_ALLOW,
325 host_content_settings_map->GetContentSetting( 316 host_content_settings_map->GetContentSetting(
326 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 317 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
327 host_content_settings_map->SetContentSettingDefaultScope( 318 host_content_settings_map->SetContentSettingDefaultScope(
328 host3, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 319 host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
329 CONTENT_SETTING_BLOCK); 320 CONTENT_SETTING_BLOCK);
330 EXPECT_EQ(CONTENT_SETTING_BLOCK, 321 EXPECT_EQ(CONTENT_SETTING_BLOCK,
331 host_content_settings_map->GetContentSetting( 322 host_content_settings_map->GetContentSetting(
332 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 323 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
333 } 324 }
334 325
335 TEST_F(HostContentSettingsMapTest, Observer) { 326 TEST_F(HostContentSettingsMapTest, Observer) {
336 TestingProfile profile; 327 TestingProfile profile;
337 HostContentSettingsMap* host_content_settings_map = 328 HostContentSettingsMap* host_content_settings_map =
338 HostContentSettingsMapFactory::GetForProfile(&profile); 329 HostContentSettingsMapFactory::GetForProfile(&profile);
339 MockSettingsObserver observer(host_content_settings_map); 330 MockSettingsObserver observer(host_content_settings_map);
340 331
341 GURL host("http://example.com/"); 332 GURL host("http://example.com/");
342 ContentSettingsPattern primary_pattern = 333 ContentSettingsPattern primary_pattern =
343 ContentSettingsPattern::FromString("[*.]example.com"); 334 ContentSettingsPattern::FromString("[*.]example.com");
344 ContentSettingsPattern secondary_pattern = 335 ContentSettingsPattern secondary_pattern =
345 ContentSettingsPattern::Wildcard(); 336 ContentSettingsPattern::Wildcard();
346 EXPECT_CALL(observer, 337 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
347 OnContentSettingsChanged(host_content_settings_map, 338 CONTENT_SETTINGS_TYPE_COOKIES,
348 CONTENT_SETTINGS_TYPE_IMAGES, 339 false, primary_pattern,
349 false, 340 secondary_pattern, false));
350 primary_pattern,
351 secondary_pattern,
352 false));
353 host_content_settings_map->SetContentSettingDefaultScope( 341 host_content_settings_map->SetContentSettingDefaultScope(
354 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 342 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
355 CONTENT_SETTING_ALLOW); 343 CONTENT_SETTING_ALLOW);
356 ::testing::Mock::VerifyAndClearExpectations(&observer); 344 ::testing::Mock::VerifyAndClearExpectations(&observer);
357 345
358 EXPECT_CALL(observer, 346 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
359 OnContentSettingsChanged(host_content_settings_map, 347 CONTENT_SETTINGS_TYPE_COOKIES,
360 CONTENT_SETTINGS_TYPE_IMAGES, false, 348 false, _, _, true));
361 _, _, true));
362 host_content_settings_map->ClearSettingsForOneType( 349 host_content_settings_map->ClearSettingsForOneType(
363 CONTENT_SETTINGS_TYPE_IMAGES); 350 CONTENT_SETTINGS_TYPE_COOKIES);
364 ::testing::Mock::VerifyAndClearExpectations(&observer); 351 ::testing::Mock::VerifyAndClearExpectations(&observer);
365 352
366 EXPECT_CALL(observer, 353 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
367 OnContentSettingsChanged(host_content_settings_map, 354 CONTENT_SETTINGS_TYPE_COOKIES,
368 CONTENT_SETTINGS_TYPE_IMAGES, false, 355 false, _, _, true));
369 _, _, true));
370 host_content_settings_map->SetDefaultContentSetting( 356 host_content_settings_map->SetDefaultContentSetting(
371 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 357 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
372 } 358 }
373 359
374 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { 360 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
375 TestingProfile profile; 361 TestingProfile profile;
376 HostContentSettingsMap* host_content_settings_map = 362 HostContentSettingsMap* host_content_settings_map =
377 HostContentSettingsMapFactory::GetForProfile(&profile); 363 HostContentSettingsMapFactory::GetForProfile(&profile);
378 364
379 PrefService* prefs = profile.GetPrefs(); 365 PrefService* prefs = profile.GetPrefs();
380 GURL host("http://example.com"); 366 GURL host("http://example.com");
381 367
382 host_content_settings_map->SetDefaultContentSetting( 368 host_content_settings_map->SetDefaultContentSetting(
383 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 369 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
384 EXPECT_EQ(CONTENT_SETTING_BLOCK, 370 EXPECT_EQ(CONTENT_SETTING_BLOCK,
385 host_content_settings_map->GetContentSetting( 371 host_content_settings_map->GetContentSetting(
386 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 372 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
387 373
388 const content_settings::WebsiteSettingsInfo* info = 374 const content_settings::WebsiteSettingsInfo* info =
389 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( 375 content_settings::WebsiteSettingsRegistry::GetInstance()->Get(
390 CONTENT_SETTINGS_TYPE_IMAGES); 376 CONTENT_SETTINGS_TYPE_COOKIES);
391 // Clearing the backing pref should also clear the internal cache. 377 // Clearing the backing pref should also clear the internal cache.
392 prefs->ClearPref(info->default_value_pref_name()); 378 prefs->ClearPref(info->default_value_pref_name());
393 EXPECT_EQ(CONTENT_SETTING_ALLOW, 379 EXPECT_EQ(CONTENT_SETTING_ALLOW,
394 host_content_settings_map->GetContentSetting( 380 host_content_settings_map->GetContentSetting(
395 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 381 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
396 382
397 // Reseting the pref to its previous value should update the cache. 383 // Reseting the pref to its previous value should update the cache.
398 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK); 384 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK);
399 EXPECT_EQ(CONTENT_SETTING_BLOCK, 385 EXPECT_EQ(CONTENT_SETTING_BLOCK,
400 host_content_settings_map->GetContentSetting( 386 host_content_settings_map->GetContentSetting(
401 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 387 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
402 } 388 }
403 389
404 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 390 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
405 TestingProfile profile; 391 TestingProfile profile;
406 HostContentSettingsMap* host_content_settings_map = 392 HostContentSettingsMap* host_content_settings_map =
407 HostContentSettingsMapFactory::GetForProfile(&profile); 393 HostContentSettingsMapFactory::GetForProfile(&profile);
408 394
409 PrefService* prefs = profile.GetPrefs(); 395 PrefService* prefs = profile.GetPrefs();
410 396
411 // Make a copy of the default pref value so we can reset it later. 397 // Make a copy of the default pref value so we can reset it later.
412 std::unique_ptr<base::Value> default_value( 398 std::unique_ptr<base::Value> default_value(
413 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 399 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES))
414 ->GetValue() 400 ->GetValue()
415 ->DeepCopy()); 401 ->DeepCopy());
416 402
417 GURL host("http://example.com"); 403 GURL host("http://example.com");
418 404
419 EXPECT_EQ(CONTENT_SETTING_ALLOW, 405 EXPECT_EQ(CONTENT_SETTING_ALLOW,
420 host_content_settings_map->GetContentSetting( 406 host_content_settings_map->GetContentSetting(
421 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 407 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
422 408
423 host_content_settings_map->SetContentSettingDefaultScope( 409 host_content_settings_map->SetContentSettingDefaultScope(
424 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 410 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
425 CONTENT_SETTING_BLOCK); 411 CONTENT_SETTING_BLOCK);
426 EXPECT_EQ(CONTENT_SETTING_BLOCK, 412 EXPECT_EQ(CONTENT_SETTING_BLOCK,
427 host_content_settings_map->GetContentSetting( 413 host_content_settings_map->GetContentSetting(
428 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 414 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
429 415
430 // Make a copy of the pref's new value so we can reset it later. 416 // Make a copy of the pref's new value so we can reset it later.
431 std::unique_ptr<base::Value> new_value( 417 std::unique_ptr<base::Value> new_value(
432 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 418 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES))
433 ->GetValue() 419 ->GetValue()
434 ->DeepCopy()); 420 ->DeepCopy());
435 421
436 // Clearing the backing pref should also clear the internal cache. 422 // Clearing the backing pref should also clear the internal cache.
437 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *default_value); 423 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *default_value);
438 EXPECT_EQ(CONTENT_SETTING_ALLOW, 424 EXPECT_EQ(CONTENT_SETTING_ALLOW,
439 host_content_settings_map->GetContentSetting( 425 host_content_settings_map->GetContentSetting(
440 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 426 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
441 427
442 // Reseting the pref to its previous value should update the cache. 428 // Reseting the pref to its previous value should update the cache.
443 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *new_value); 429 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *new_value);
444 EXPECT_EQ(CONTENT_SETTING_BLOCK, 430 EXPECT_EQ(CONTENT_SETTING_BLOCK,
445 host_content_settings_map->GetContentSetting( 431 host_content_settings_map->GetContentSetting(
446 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 432 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
447 } 433 }
448 434
449 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 435 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
450 TestingProfile profile; 436 TestingProfile profile;
451 HostContentSettingsMap* host_content_settings_map = 437 HostContentSettingsMap* host_content_settings_map =
452 HostContentSettingsMapFactory::GetForProfile(&profile); 438 HostContentSettingsMapFactory::GetForProfile(&profile);
453 content_settings::CookieSettings* cookie_settings = 439 content_settings::CookieSettings* cookie_settings =
454 CookieSettingsFactory::GetForProfile(&profile).get(); 440 CookieSettingsFactory::GetForProfile(&profile).get();
455 441
456 GURL host_ending_with_dot("http://example.com./"); 442 GURL host_ending_with_dot("http://example.com./");
457 443
458 EXPECT_EQ(CONTENT_SETTING_ALLOW,
459 host_content_settings_map->GetContentSetting(
460 host_ending_with_dot,
461 host_ending_with_dot,
462 CONTENT_SETTINGS_TYPE_IMAGES,
463 std::string()));
464 host_content_settings_map->SetContentSettingDefaultScope(
465 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
466 CONTENT_SETTING_DEFAULT);
467 EXPECT_EQ(
468 CONTENT_SETTING_ALLOW,
469 host_content_settings_map->GetContentSetting(host_ending_with_dot,
470 host_ending_with_dot,
471 CONTENT_SETTINGS_TYPE_IMAGES,
472 std::string()));
473 host_content_settings_map->SetContentSettingDefaultScope(
474 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(),
475 CONTENT_SETTING_BLOCK);
476 EXPECT_EQ(
477 CONTENT_SETTING_BLOCK,
478 host_content_settings_map->GetContentSetting(host_ending_with_dot,
479 host_ending_with_dot,
480 CONTENT_SETTINGS_TYPE_IMAGES,
481 std::string()));
482
483 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 444 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
484 host_ending_with_dot, host_ending_with_dot)); 445 host_ending_with_dot, host_ending_with_dot));
485 host_content_settings_map->SetContentSettingDefaultScope( 446 host_content_settings_map->SetContentSettingDefaultScope(
486 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, 447 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
487 std::string(), CONTENT_SETTING_DEFAULT); 448 std::string(), CONTENT_SETTING_DEFAULT);
488 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( 449 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
489 host_ending_with_dot, host_ending_with_dot)); 450 host_ending_with_dot, host_ending_with_dot));
490 host_content_settings_map->SetContentSettingDefaultScope( 451 host_content_settings_map->SetContentSettingDefaultScope(
491 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, 452 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
492 std::string(), CONTENT_SETTING_BLOCK); 453 std::string(), CONTENT_SETTING_BLOCK);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 TEST_F(HostContentSettingsMapTest, NestedSettings) { 573 TEST_F(HostContentSettingsMapTest, NestedSettings) {
613 TestingProfile profile; 574 TestingProfile profile;
614 HostContentSettingsMap* host_content_settings_map = 575 HostContentSettingsMap* host_content_settings_map =
615 HostContentSettingsMapFactory::GetForProfile(&profile); 576 HostContentSettingsMapFactory::GetForProfile(&profile);
616 577
617 GURL host("http://a.b.example.com/"); 578 GURL host("http://a.b.example.com/");
618 GURL host1("http://example.com/"); 579 GURL host1("http://example.com/");
619 GURL host2("http://b.example.com/"); 580 GURL host2("http://b.example.com/");
620 581
621 host_content_settings_map->SetContentSettingDefaultScope( 582 host_content_settings_map->SetContentSettingDefaultScope(
622 host1, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 583 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
623 CONTENT_SETTING_BLOCK); 584 CONTENT_SETTING_BLOCK);
624 585
625 host_content_settings_map->SetContentSettingDefaultScope( 586 host_content_settings_map->SetContentSettingDefaultScope(
626 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 587 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
627 CONTENT_SETTING_BLOCK); 588 CONTENT_SETTING_BLOCK);
628 589
629 host_content_settings_map->SetContentSettingDefaultScope( 590 host_content_settings_map->SetContentSettingDefaultScope(
630 host, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), 591 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(),
631 CONTENT_SETTING_BLOCK); 592 CONTENT_SETTING_BLOCK);
632 host_content_settings_map->SetDefaultContentSetting( 593 host_content_settings_map->SetDefaultContentSetting(
633 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 594 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
634 595
635 EXPECT_EQ(CONTENT_SETTING_BLOCK, 596 EXPECT_EQ(CONTENT_SETTING_BLOCK,
636 host_content_settings_map->GetContentSetting( 597 host_content_settings_map->GetContentSetting(
637 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 598 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
638 EXPECT_EQ(CONTENT_SETTING_BLOCK, 599 EXPECT_EQ(CONTENT_SETTING_BLOCK,
639 host_content_settings_map->GetContentSetting( 600 host_content_settings_map->GetContentSetting(
640 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 601 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
641 EXPECT_EQ(CONTENT_SETTING_BLOCK, 602 EXPECT_EQ(CONTENT_SETTING_BLOCK,
642 host_content_settings_map->GetContentSetting( 603 host_content_settings_map->GetContentSetting(
643 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 604 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
644 EXPECT_EQ(CONTENT_SETTING_BLOCK, 605 EXPECT_EQ(CONTENT_SETTING_BLOCK,
645 host_content_settings_map->GetContentSetting( 606 host_content_settings_map->GetContentSetting(
646 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, std::string())); 607 host, host, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
647 EXPECT_EQ(CONTENT_SETTING_BLOCK, 608 std::string()));
648 host_content_settings_map->GetContentSetting(
649 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
650 EXPECT_EQ(CONTENT_SETTING_ASK, 609 EXPECT_EQ(CONTENT_SETTING_ASK,
651 host_content_settings_map->GetContentSetting( 610 host_content_settings_map->GetContentSetting(
652 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 611 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
653 EXPECT_EQ( 612 EXPECT_EQ(
654 CONTENT_SETTING_ASK, 613 CONTENT_SETTING_ASK,
655 host_content_settings_map->GetContentSetting( 614 host_content_settings_map->GetContentSetting(
656 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 615 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
657 EXPECT_EQ(CONTENT_SETTING_ASK, 616 EXPECT_EQ(CONTENT_SETTING_ASK,
658 host_content_settings_map->GetContentSetting( 617 host_content_settings_map->GetContentSetting(
659 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 618 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
619 #if !defined(OS_ANDROID)
660 EXPECT_EQ(CONTENT_SETTING_ASK, 620 EXPECT_EQ(CONTENT_SETTING_ASK,
661 host_content_settings_map->GetContentSetting( 621 host_content_settings_map->GetContentSetting(
662 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); 622 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
623 #endif
663 EXPECT_EQ(CONTENT_SETTING_BLOCK, 624 EXPECT_EQ(CONTENT_SETTING_BLOCK,
664 host_content_settings_map->GetContentSetting( 625 host_content_settings_map->GetContentSetting(
665 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 626 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
666 EXPECT_EQ(CONTENT_SETTING_ALLOW, 627 EXPECT_EQ(CONTENT_SETTING_ALLOW,
667 host_content_settings_map->GetContentSetting( 628 host_content_settings_map->GetContentSetting(
668 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 629 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
669 } 630 }
670 631
671 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 632 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
672 TestingProfile profile; 633 TestingProfile profile;
673 Profile* otr_profile = profile.GetOffTheRecordProfile(); 634 Profile* otr_profile = profile.GetOffTheRecordProfile();
674 HostContentSettingsMap* host_content_settings_map = 635 HostContentSettingsMap* host_content_settings_map =
675 HostContentSettingsMapFactory::GetForProfile(&profile); 636 HostContentSettingsMapFactory::GetForProfile(&profile);
676 HostContentSettingsMap* otr_map = 637 HostContentSettingsMap* otr_map =
677 HostContentSettingsMapFactory::GetForProfile(otr_profile); 638 HostContentSettingsMapFactory::GetForProfile(otr_profile);
678 639
679 GURL host("http://example.com/"); 640 GURL host("http://example.com/");
680 641
681 EXPECT_EQ(CONTENT_SETTING_ALLOW, 642 EXPECT_EQ(CONTENT_SETTING_ALLOW,
682 host_content_settings_map->GetContentSetting( 643 host_content_settings_map->GetContentSetting(
683 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 644 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
684 EXPECT_EQ(CONTENT_SETTING_ALLOW, 645 EXPECT_EQ(CONTENT_SETTING_ALLOW,
685 otr_map->GetContentSetting( 646 otr_map->GetContentSetting(
686 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 647 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
687 648
688 // Changing content settings on the main map should also affect the 649 // Changing content settings on the main map should also affect the
689 // incognito map. 650 // incognito map.
690 host_content_settings_map->SetContentSettingDefaultScope( 651 host_content_settings_map->SetContentSettingDefaultScope(
691 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 652 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
692 CONTENT_SETTING_BLOCK); 653 CONTENT_SETTING_BLOCK);
693 EXPECT_EQ(CONTENT_SETTING_BLOCK, 654 EXPECT_EQ(CONTENT_SETTING_BLOCK,
694 host_content_settings_map->GetContentSetting( 655 host_content_settings_map->GetContentSetting(
695 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 656 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
696 EXPECT_EQ(CONTENT_SETTING_BLOCK, 657 EXPECT_EQ(CONTENT_SETTING_BLOCK,
697 otr_map->GetContentSetting( 658 otr_map->GetContentSetting(
698 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 659 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
699 660
700 // Changing content settings on the incognito map should NOT affect the 661 // Changing content settings on the incognito map should NOT affect the
701 // main map. 662 // main map.
702 otr_map->SetContentSettingDefaultScope(host, GURL(), 663 otr_map->SetContentSettingDefaultScope(host, GURL(),
703 CONTENT_SETTINGS_TYPE_IMAGES, 664 CONTENT_SETTINGS_TYPE_COOKIES,
704 std::string(), CONTENT_SETTING_ALLOW); 665 std::string(), CONTENT_SETTING_ALLOW);
705 EXPECT_EQ(CONTENT_SETTING_BLOCK, 666 EXPECT_EQ(CONTENT_SETTING_BLOCK,
706 host_content_settings_map->GetContentSetting( 667 host_content_settings_map->GetContentSetting(
707 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 668 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
708 EXPECT_EQ(CONTENT_SETTING_ALLOW, 669 EXPECT_EQ(CONTENT_SETTING_ALLOW,
709 otr_map->GetContentSetting( 670 otr_map->GetContentSetting(
710 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 671 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
711 } 672 }
712 673
713 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { 674 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) {
714 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in 675 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in
715 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK 676 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK
716 // settings from regular to incognito. 677 // settings from regular to incognito.
717 TestingProfile profile; 678 TestingProfile profile;
718 Profile* otr_profile = profile.GetOffTheRecordProfile(); 679 Profile* otr_profile = profile.GetOffTheRecordProfile();
719 HostContentSettingsMap* host_content_settings_map = 680 HostContentSettingsMap* host_content_settings_map =
720 HostContentSettingsMapFactory::GetForProfile(&profile); 681 HostContentSettingsMapFactory::GetForProfile(&profile);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 862
902 // For a single Unicode encoded pattern, check if it gets converted to punycode 863 // For a single Unicode encoded pattern, check if it gets converted to punycode
903 // and old pattern gets deleted. 864 // and old pattern gets deleted.
904 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 865 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
905 TestingProfile profile; 866 TestingProfile profile;
906 PrefService* prefs = profile.GetPrefs(); 867 PrefService* prefs = profile.GetPrefs();
907 868
908 // Set utf-8 data. 869 // Set utf-8 data.
909 { 870 {
910 DictionaryPrefUpdate update(prefs, 871 DictionaryPrefUpdate update(prefs,
911 GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); 872 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
912 base::DictionaryValue* all_settings_dictionary = update.Get(); 873 base::DictionaryValue* all_settings_dictionary = update.Get();
913 ASSERT_TRUE(NULL != all_settings_dictionary); 874 ASSERT_TRUE(NULL != all_settings_dictionary);
914 875
915 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 876 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
916 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); 877 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
917 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 878 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
918 dummy_payload); 879 dummy_payload);
919 } 880 }
920 881
921 HostContentSettingsMapFactory::GetForProfile(&profile); 882 HostContentSettingsMapFactory::GetForProfile(&profile);
922 883
923 const base::DictionaryValue* all_settings_dictionary = 884 const base::DictionaryValue* all_settings_dictionary =
924 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); 885 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
925 const base::DictionaryValue* result = NULL; 886 const base::DictionaryValue* result = NULL;
926 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 887 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
927 "[*.]\xC4\x87ira.com,*", &result)); 888 "[*.]\xC4\x87ira.com,*", &result));
928 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 889 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
929 "[*.]xn--ira-ppa.com,*", &result)); 890 "[*.]xn--ira-ppa.com,*", &result));
930 } 891 }
931 892
932 // If both Unicode and its punycode pattern exist, make sure we don't touch the 893 // If both Unicode and its punycode pattern exist, make sure we don't touch the
933 // settings for the punycode, and that Unicode pattern gets deleted. 894 // settings for the punycode, and that Unicode pattern gets deleted.
934 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 895 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 EXPECT_EQ(CONTENT_SETTING_BLOCK, 936 EXPECT_EQ(CONTENT_SETTING_BLOCK,
976 host_content_settings_map->GetDefaultContentSetting( 937 host_content_settings_map->GetDefaultContentSetting(
977 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 938 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
978 939
979 // Remove managed-default-content-settings-preferences. 940 // Remove managed-default-content-settings-preferences.
980 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting); 941 prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
981 EXPECT_EQ(CONTENT_SETTING_ALLOW, 942 EXPECT_EQ(CONTENT_SETTING_ALLOW,
982 host_content_settings_map->GetDefaultContentSetting( 943 host_content_settings_map->GetDefaultContentSetting(
983 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 944 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
984 945
946 #if defined(ENABLE_PLUGINS)
985 // Set preference to manage the default-content-setting for Plugins. 947 // Set preference to manage the default-content-setting for Plugins.
986 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 948 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
987 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 949 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
988 EXPECT_EQ(CONTENT_SETTING_BLOCK, 950 EXPECT_EQ(CONTENT_SETTING_BLOCK,
989 host_content_settings_map->GetDefaultContentSetting( 951 host_content_settings_map->GetDefaultContentSetting(
990 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 952 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
991 953
992 #if defined(ENABLE_PLUGINS)
993 // Remove the preference to manage the default-content-setting for Plugins. 954 // Remove the preference to manage the default-content-setting for Plugins.
994 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 955 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
995 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 956 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
996 host_content_settings_map->GetDefaultContentSetting( 957 host_content_settings_map->GetDefaultContentSetting(
997 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 958 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
998 #endif 959 #endif
999 960
1000 EXPECT_EQ(CONTENT_SETTING_BLOCK, 961 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1001 host_content_settings_map->GetDefaultContentSetting( 962 host_content_settings_map->GetDefaultContentSetting(
1002 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); 963 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 // If a setting for a default-content-setting-type is set while the type is 1082 // If a setting for a default-content-setting-type is set while the type is
1122 // managed, then the new setting should be preserved and used after the 1083 // managed, then the new setting should be preserved and used after the
1123 // default-content-setting-type is not managed anymore. 1084 // default-content-setting-type is not managed anymore.
1124 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { 1085 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
1125 TestingProfile profile; 1086 TestingProfile profile;
1126 HostContentSettingsMap* host_content_settings_map = 1087 HostContentSettingsMap* host_content_settings_map =
1127 HostContentSettingsMapFactory::GetForProfile(&profile); 1088 HostContentSettingsMapFactory::GetForProfile(&profile);
1128 syncable_prefs::TestingPrefServiceSyncable* prefs = 1089 syncable_prefs::TestingPrefServiceSyncable* prefs =
1129 profile.GetTestingPrefService(); 1090 profile.GetTestingPrefService();
1130 1091
1131 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 1092 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
1132 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 1093 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
1133 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1094 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1134 host_content_settings_map->GetDefaultContentSetting( 1095 host_content_settings_map->GetDefaultContentSetting(
1135 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1096 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1136 1097
1137 host_content_settings_map->SetDefaultContentSetting( 1098 host_content_settings_map->SetDefaultContentSetting(
1138 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 1099 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1139 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1100 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1140 host_content_settings_map->GetDefaultContentSetting( 1101 host_content_settings_map->GetDefaultContentSetting(
1141 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1102 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1142 1103
1143 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 1104 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
1144 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1105 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1145 host_content_settings_map->GetDefaultContentSetting( 1106 host_content_settings_map->GetDefaultContentSetting(
1146 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1107 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
1147 } 1108 }
1148 1109
1149 TEST_F(HostContentSettingsMapTest, GetContentSetting) { 1110 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
1150 TestingProfile profile; 1111 TestingProfile profile;
1151 HostContentSettingsMap* host_content_settings_map = 1112 HostContentSettingsMap* host_content_settings_map =
1152 HostContentSettingsMapFactory::GetForProfile(&profile); 1113 HostContentSettingsMapFactory::GetForProfile(&profile);
1153 1114
1154 GURL host("http://example.com/"); 1115 GURL host("http://example.com/");
1155 GURL embedder("chrome://foo"); 1116 GURL embedder("chrome://foo");
1156 host_content_settings_map->SetContentSettingDefaultScope( 1117 host_content_settings_map->SetContentSettingDefaultScope(
1157 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 1118 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
1158 CONTENT_SETTING_BLOCK); 1119 CONTENT_SETTING_BLOCK);
1159 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1120 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1160 host_content_settings_map->GetContentSetting( 1121 host_content_settings_map->GetContentSetting(
1161 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1122 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1162 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1123 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1163 host_content_settings_map->GetContentSetting( 1124 host_content_settings_map->GetContentSetting(
1164 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1125 embedder, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1165 } 1126 }
1166 1127
1167 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) { 1128 TEST_F(HostContentSettingsMapTest, IsDefaultSettingAllowedForType) {
1168 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( 1129 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType(
1169 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); 1130 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
1170 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType( 1131 EXPECT_FALSE(HostContentSettingsMap::IsDefaultSettingAllowedForType(
1171 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 1132 CONTENT_SETTING_ALLOW, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
1172 } 1133 }
1173 1134
1174 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { 1135 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
1175 TestingProfile profile; 1136 TestingProfile profile;
1176 HostContentSettingsMap* host_content_settings_map = 1137 HostContentSettingsMap* host_content_settings_map =
1177 HostContentSettingsMapFactory::GetForProfile(&profile); 1138 HostContentSettingsMapFactory::GetForProfile(&profile);
1178 content_settings::MockObserver mock_observer; 1139 content_settings::MockObserver mock_observer;
1179 1140
1180 GURL host("http://example.com/"); 1141 GURL host("http://example.com/");
1181 ContentSettingsPattern pattern = 1142 ContentSettingsPattern pattern =
1182 ContentSettingsPattern::FromString("[*.]example.com"); 1143 ContentSettingsPattern::FromString("[*.]example.com");
1183 EXPECT_CALL(mock_observer, 1144 EXPECT_CALL(mock_observer, OnContentSettingChanged(
1184 OnContentSettingChanged(pattern, 1145 pattern, ContentSettingsPattern::Wildcard(),
1185 ContentSettingsPattern::Wildcard(), 1146 CONTENT_SETTINGS_TYPE_COOKIES, ""));
1186 CONTENT_SETTINGS_TYPE_IMAGES,
1187 ""));
1188 1147
1189 host_content_settings_map->AddObserver(&mock_observer); 1148 host_content_settings_map->AddObserver(&mock_observer);
1190 1149
1191 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1150 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1192 host_content_settings_map->GetContentSetting( 1151 host_content_settings_map->GetContentSetting(
1193 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1152 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1194 host_content_settings_map->SetContentSettingDefaultScope( 1153 host_content_settings_map->SetContentSettingDefaultScope(
1195 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 1154 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
1196 CONTENT_SETTING_DEFAULT); 1155 CONTENT_SETTING_DEFAULT);
1197 } 1156 }
1198 1157
1199 TEST_F(HostContentSettingsMapTest, GuestProfile) { 1158 TEST_F(HostContentSettingsMapTest, GuestProfile) {
1200 TestingProfile profile; 1159 TestingProfile profile;
1201 profile.SetGuestSession(true); 1160 profile.SetGuestSession(true);
1202 HostContentSettingsMap* host_content_settings_map = 1161 HostContentSettingsMap* host_content_settings_map =
1203 HostContentSettingsMapFactory::GetForProfile(&profile); 1162 HostContentSettingsMapFactory::GetForProfile(&profile);
1204 1163
1205 GURL host("http://example.com/"); 1164 GURL host("http://example.com/");
1206 ContentSettingsPattern pattern = 1165 ContentSettingsPattern pattern =
1207 ContentSettingsPattern::FromString("[*.]example.com"); 1166 ContentSettingsPattern::FromString("[*.]example.com");
1208 1167
1209 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1168 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1210 host_content_settings_map->GetContentSetting( 1169 host_content_settings_map->GetContentSetting(
1211 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1170 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1212 1171
1213 // Changing content settings should not result in any prefs being stored 1172 // Changing content settings should not result in any prefs being stored
1214 // however the value should be set in memory. 1173 // however the value should be set in memory.
1215 host_content_settings_map->SetContentSettingDefaultScope( 1174 host_content_settings_map->SetContentSettingDefaultScope(
1216 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), 1175 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
1217 CONTENT_SETTING_BLOCK); 1176 CONTENT_SETTING_BLOCK);
1218 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1177 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1219 host_content_settings_map->GetContentSetting( 1178 host_content_settings_map->GetContentSetting(
1220 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1179 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1221 1180
1222 const base::DictionaryValue* all_settings_dictionary = 1181 const base::DictionaryValue* all_settings_dictionary =
1223 profile.GetPrefs()->GetDictionary( 1182 profile.GetPrefs()->GetDictionary(
1224 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1183 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
1225 EXPECT_TRUE(all_settings_dictionary->empty()); 1184 EXPECT_TRUE(all_settings_dictionary->empty());
1226 } 1185 }
1227 1186
1228 // Default settings should not be modifiable for the guest profile (there is no 1187 // Default settings should not be modifiable for the guest profile (there is no
1229 // UI to do this). 1188 // UI to do this).
1230 TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { 1189 TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) {
1231 TestingProfile profile; 1190 TestingProfile profile;
1232 profile.SetGuestSession(true); 1191 profile.SetGuestSession(true);
1233 HostContentSettingsMap* host_content_settings_map = 1192 HostContentSettingsMap* host_content_settings_map =
1234 HostContentSettingsMapFactory::GetForProfile(&profile); 1193 HostContentSettingsMapFactory::GetForProfile(&profile);
1235 1194
1236 GURL host("http://example.com/"); 1195 GURL host("http://example.com/");
1237 1196
1238 // There are no custom rules, so this should be the default. 1197 // There are no custom rules, so this should be the default.
1239 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1198 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1240 host_content_settings_map->GetContentSetting( 1199 host_content_settings_map->GetContentSetting(
1241 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1200 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1242 1201
1243 host_content_settings_map->SetDefaultContentSetting( 1202 host_content_settings_map->SetDefaultContentSetting(
1244 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 1203 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1245 1204
1246 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1205 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1247 host_content_settings_map->GetContentSetting( 1206 host_content_settings_map->GetContentSetting(
1248 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1207 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1249 } 1208 }
1250 1209
1251 // We used to incorrectly store content settings in prefs for the guest profile. 1210 // We used to incorrectly store content settings in prefs for the guest profile.
1252 // We need to ensure these get deleted appropriately. 1211 // We need to ensure these get deleted appropriately.
1253 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) { 1212 TEST_F(HostContentSettingsMapTest, GuestProfileMigration) {
1254 TestingProfile profile; 1213 TestingProfile profile;
1255 profile.SetGuestSession(true); 1214 profile.SetGuestSession(true);
1256 1215
1257 // Set a pref manually in the guest profile. 1216 // Set a pref manually in the guest profile.
1258 std::unique_ptr<base::Value> value = 1217 std::unique_ptr<base::Value> value =
1259 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); 1218 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}");
1260 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); 1219 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value);
1261 1220
1262 // Test that during construction all the prefs get cleared. 1221 // Test that during construction all the prefs get cleared.
1263 HostContentSettingsMapFactory::GetForProfile(&profile); 1222 HostContentSettingsMapFactory::GetForProfile(&profile);
1264 1223
1265 const base::DictionaryValue* all_settings_dictionary = 1224 const base::DictionaryValue* all_settings_dictionary =
1266 profile.GetPrefs()->GetDictionary( 1225 profile.GetPrefs()->GetDictionary(
1267 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); 1226 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
1268 EXPECT_TRUE(all_settings_dictionary->empty()); 1227 EXPECT_TRUE(all_settings_dictionary->empty());
1269 } 1228 }
1270 1229
1271 TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) { 1230 TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) {
1272 TestingProfile profile; 1231 TestingProfile profile;
1273 HostContentSettingsMap* host_content_settings_map = 1232 HostContentSettingsMap* host_content_settings_map =
1274 HostContentSettingsMapFactory::GetForProfile(&profile); 1233 HostContentSettingsMapFactory::GetForProfile(&profile);
1275 1234
1276 // Set old formatted settings. 1235 // Set old formatted settings.
1277 GURL host("http://example.com/"); 1236 GURL host("http://example.com/");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 1269 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1311 1270
1312 // After migrating old settings, changes to the setting works. 1271 // After migrating old settings, changes to the setting works.
1313 host_content_settings_map->SetContentSettingDefaultScope( 1272 host_content_settings_map->SetContentSettingDefaultScope(
1314 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), 1273 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1315 CONTENT_SETTING_BLOCK); 1274 CONTENT_SETTING_BLOCK);
1316 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1275 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1317 host_content_settings_map->GetContentSetting( 1276 host_content_settings_map->GetContentSetting(
1318 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 1277 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1319 } 1278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698