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 "components/content_settings/core/browser/content_settings_pref_provide
r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 MockObserver mock_observer; | 120 MockObserver mock_observer; |
121 EXPECT_CALL(mock_observer, OnContentSettingChanged( | 121 EXPECT_CALL(mock_observer, OnContentSettingChanged( |
122 pattern, ContentSettingsPattern::Wildcard(), | 122 pattern, ContentSettingsPattern::Wildcard(), |
123 CONTENT_SETTINGS_TYPE_COOKIES, "")); | 123 CONTENT_SETTINGS_TYPE_COOKIES, "")); |
124 | 124 |
125 pref_content_settings_provider.AddObserver(&mock_observer); | 125 pref_content_settings_provider.AddObserver(&mock_observer); |
126 | 126 |
127 pref_content_settings_provider.SetWebsiteSetting( | 127 pref_content_settings_provider.SetWebsiteSetting( |
128 pattern, ContentSettingsPattern::Wildcard(), | 128 pattern, ContentSettingsPattern::Wildcard(), |
129 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 129 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
130 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 130 new base::Value(CONTENT_SETTING_ALLOW)); |
131 | 131 |
132 pref_content_settings_provider.ShutdownOnUIThread(); | 132 pref_content_settings_provider.ShutdownOnUIThread(); |
133 } | 133 } |
134 | 134 |
135 // Tests that fullscreen and mouselock content settings are cleared. | 135 // Tests that fullscreen and mouselock content settings are cleared. |
136 TEST_F(PrefProviderTest, DiscardObsoletePreferences) { | 136 TEST_F(PrefProviderTest, DiscardObsoletePreferences) { |
137 static const char kFullscreenPrefPath[] = | 137 static const char kFullscreenPrefPath[] = |
138 "profile.content_settings.exceptions.fullscreen"; | 138 "profile.content_settings.exceptions.fullscreen"; |
139 #if !defined(OS_ANDROID) | 139 #if !defined(OS_ANDROID) |
140 static const char kMouselockPrefPath[] = | 140 static const char kMouselockPrefPath[] = |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 TestingProfile::Builder otr_profile_builder; | 209 TestingProfile::Builder otr_profile_builder; |
210 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); | 210 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); |
211 otr_profile_builder.BuildIncognito(profile.get()); | 211 otr_profile_builder.BuildIncognito(profile.get()); |
212 | 212 |
213 PrefProvider pref_content_settings_provider(regular_prefs, false); | 213 PrefProvider pref_content_settings_provider(regular_prefs, false); |
214 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); | 214 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); |
215 ContentSettingsPattern pattern = | 215 ContentSettingsPattern pattern = |
216 ContentSettingsPattern::FromString("[*.]example.com"); | 216 ContentSettingsPattern::FromString("[*.]example.com"); |
217 pref_content_settings_provider.SetWebsiteSetting( | 217 pref_content_settings_provider.SetWebsiteSetting( |
218 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 218 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
219 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 219 new base::Value(CONTENT_SETTING_ALLOW)); |
220 | 220 |
221 GURL host("http://example.com/"); | 221 GURL host("http://example.com/"); |
222 // The value should of course be visible in the regular PrefProvider. | 222 // The value should of course be visible in the regular PrefProvider. |
223 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 223 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
224 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | 224 TestUtils::GetContentSetting(&pref_content_settings_provider, host, |
225 host, CONTENT_SETTINGS_TYPE_COOKIES, | 225 host, CONTENT_SETTINGS_TYPE_COOKIES, |
226 std::string(), false)); | 226 std::string(), false)); |
227 // And also in the OTR version. | 227 // And also in the OTR version. |
228 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 228 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
229 TestUtils::GetContentSetting( | 229 TestUtils::GetContentSetting( |
(...skipping 20 matching lines...) Expand all Loading... |
250 TestUtils::GetContentSetting(&provider, primary_url, primary_url, | 250 TestUtils::GetContentSetting(&provider, primary_url, primary_url, |
251 CONTENT_SETTINGS_TYPE_COOKIES, | 251 CONTENT_SETTINGS_TYPE_COOKIES, |
252 std::string(), false)); | 252 std::string(), false)); |
253 | 253 |
254 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( | 254 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( |
255 &provider, primary_url, primary_url, | 255 &provider, primary_url, primary_url, |
256 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); | 256 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); |
257 | 257 |
258 provider.SetWebsiteSetting(primary_pattern, primary_pattern, | 258 provider.SetWebsiteSetting(primary_pattern, primary_pattern, |
259 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 259 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
260 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 260 new base::Value(CONTENT_SETTING_BLOCK)); |
261 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 261 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
262 TestUtils::GetContentSetting(&provider, primary_url, primary_url, | 262 TestUtils::GetContentSetting(&provider, primary_url, primary_url, |
263 CONTENT_SETTINGS_TYPE_COOKIES, | 263 CONTENT_SETTINGS_TYPE_COOKIES, |
264 std::string(), false)); | 264 std::string(), false)); |
265 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( | 265 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( |
266 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_COOKIES, | 266 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_COOKIES, |
267 std::string(), false)); | 267 std::string(), false)); |
268 int int_value = -1; | 268 int int_value = -1; |
269 value_ptr->GetAsInteger(&int_value); | 269 value_ptr->GetAsInteger(&int_value); |
270 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); | 270 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); |
(...skipping 22 matching lines...) Expand all Loading... |
293 ContentSettingsPattern::FromString("example.org"); | 293 ContentSettingsPattern::FromString("example.org"); |
294 ContentSettingsPattern pattern3 = | 294 ContentSettingsPattern pattern3 = |
295 ContentSettingsPattern::FromString("file:///tmp/test.html"); | 295 ContentSettingsPattern::FromString("file:///tmp/test.html"); |
296 | 296 |
297 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 297 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
298 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, | 298 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, |
299 host1, CONTENT_SETTINGS_TYPE_COOKIES, | 299 host1, CONTENT_SETTINGS_TYPE_COOKIES, |
300 std::string(), false)); | 300 std::string(), false)); |
301 pref_content_settings_provider.SetWebsiteSetting( | 301 pref_content_settings_provider.SetWebsiteSetting( |
302 pattern1, pattern1, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 302 pattern1, pattern1, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
303 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 303 new base::Value(CONTENT_SETTING_BLOCK)); |
304 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 304 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
305 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, | 305 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, |
306 host1, CONTENT_SETTINGS_TYPE_COOKIES, | 306 host1, CONTENT_SETTINGS_TYPE_COOKIES, |
307 std::string(), false)); | 307 std::string(), false)); |
308 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 308 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
309 TestUtils::GetContentSetting(&pref_content_settings_provider, host2, | 309 TestUtils::GetContentSetting(&pref_content_settings_provider, host2, |
310 host2, CONTENT_SETTINGS_TYPE_COOKIES, | 310 host2, CONTENT_SETTINGS_TYPE_COOKIES, |
311 std::string(), false)); | 311 std::string(), false)); |
312 | 312 |
313 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 313 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
314 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, | 314 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, |
315 host3, CONTENT_SETTINGS_TYPE_COOKIES, | 315 host3, CONTENT_SETTINGS_TYPE_COOKIES, |
316 std::string(), false)); | 316 std::string(), false)); |
317 pref_content_settings_provider.SetWebsiteSetting( | 317 pref_content_settings_provider.SetWebsiteSetting( |
318 pattern2, pattern2, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 318 pattern2, pattern2, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
319 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 319 new base::Value(CONTENT_SETTING_BLOCK)); |
320 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 320 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
321 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, | 321 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, |
322 host3, CONTENT_SETTINGS_TYPE_COOKIES, | 322 host3, CONTENT_SETTINGS_TYPE_COOKIES, |
323 std::string(), false)); | 323 std::string(), false)); |
324 | 324 |
325 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 325 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
326 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, | 326 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, |
327 host4, CONTENT_SETTINGS_TYPE_COOKIES, | 327 host4, CONTENT_SETTINGS_TYPE_COOKIES, |
328 std::string(), false)); | 328 std::string(), false)); |
329 pref_content_settings_provider.SetWebsiteSetting( | 329 pref_content_settings_provider.SetWebsiteSetting( |
330 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 330 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
331 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 331 new base::Value(CONTENT_SETTING_BLOCK)); |
332 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 332 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
333 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, | 333 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, |
334 host4, CONTENT_SETTINGS_TYPE_COOKIES, | 334 host4, CONTENT_SETTINGS_TYPE_COOKIES, |
335 std::string(), false)); | 335 std::string(), false)); |
336 | 336 |
337 pref_content_settings_provider.ShutdownOnUIThread(); | 337 pref_content_settings_provider.ShutdownOnUIThread(); |
338 } | 338 } |
339 | 339 |
340 #if defined(ENABLE_PLUGINS) | 340 #if defined(ENABLE_PLUGINS) |
341 TEST_F(PrefProviderTest, ResourceIdentifier) { | 341 TEST_F(PrefProviderTest, ResourceIdentifier) { |
342 TestingProfile testing_profile; | 342 TestingProfile testing_profile; |
343 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | 343 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), |
344 false); | 344 false); |
345 | 345 |
346 GURL host("http://example.com/"); | 346 GURL host("http://example.com/"); |
347 ContentSettingsPattern pattern = | 347 ContentSettingsPattern pattern = |
348 ContentSettingsPattern::FromString("[*.]example.com"); | 348 ContentSettingsPattern::FromString("[*.]example.com"); |
349 std::string resource1("someplugin"); | 349 std::string resource1("someplugin"); |
350 std::string resource2("otherplugin"); | 350 std::string resource2("otherplugin"); |
351 | 351 |
352 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 352 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
353 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | 353 TestUtils::GetContentSetting(&pref_content_settings_provider, host, |
354 host, CONTENT_SETTINGS_TYPE_PLUGINS, | 354 host, CONTENT_SETTINGS_TYPE_PLUGINS, |
355 resource1, false)); | 355 resource1, false)); |
356 pref_content_settings_provider.SetWebsiteSetting( | 356 pref_content_settings_provider.SetWebsiteSetting( |
357 pattern, | 357 pattern, |
358 pattern, | 358 pattern, |
359 CONTENT_SETTINGS_TYPE_PLUGINS, | 359 CONTENT_SETTINGS_TYPE_PLUGINS, |
360 resource1, | 360 resource1, |
361 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | 361 new base::Value(CONTENT_SETTING_BLOCK)); |
362 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 362 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
363 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | 363 TestUtils::GetContentSetting(&pref_content_settings_provider, host, |
364 host, CONTENT_SETTINGS_TYPE_PLUGINS, | 364 host, CONTENT_SETTINGS_TYPE_PLUGINS, |
365 resource1, false)); | 365 resource1, false)); |
366 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 366 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
367 TestUtils::GetContentSetting(&pref_content_settings_provider, host, | 367 TestUtils::GetContentSetting(&pref_content_settings_provider, host, |
368 host, CONTENT_SETTINGS_TYPE_PLUGINS, | 368 host, CONTENT_SETTINGS_TYPE_PLUGINS, |
369 resource2, false)); | 369 resource2, false)); |
370 | 370 |
371 pref_content_settings_provider.ShutdownOnUIThread(); | 371 pref_content_settings_provider.ShutdownOnUIThread(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 sync_preferences::TestingPrefServiceSyncable prefs; | 436 sync_preferences::TestingPrefServiceSyncable prefs; |
437 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 437 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
438 | 438 |
439 ContentSettingsPattern pattern_1 = | 439 ContentSettingsPattern pattern_1 = |
440 ContentSettingsPattern::FromString("google.com"); | 440 ContentSettingsPattern::FromString("google.com"); |
441 ContentSettingsPattern pattern_2 = | 441 ContentSettingsPattern pattern_2 = |
442 ContentSettingsPattern::FromString("www.google.com"); | 442 ContentSettingsPattern::FromString("www.google.com"); |
443 ContentSettingsPattern wildcard = | 443 ContentSettingsPattern wildcard = |
444 ContentSettingsPattern::FromString("*"); | 444 ContentSettingsPattern::FromString("*"); |
445 std::unique_ptr<base::Value> value( | 445 std::unique_ptr<base::Value> value( |
446 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 446 new base::Value(CONTENT_SETTING_ALLOW)); |
447 | 447 |
448 // Create a normal provider and set a setting. | 448 // Create a normal provider and set a setting. |
449 PrefProvider normal_provider(&prefs, false); | 449 PrefProvider normal_provider(&prefs, false); |
450 normal_provider.SetWebsiteSetting(pattern_1, wildcard, | 450 normal_provider.SetWebsiteSetting(pattern_1, wildcard, |
451 CONTENT_SETTINGS_TYPE_COOKIES, | 451 CONTENT_SETTINGS_TYPE_COOKIES, |
452 std::string(), value->DeepCopy()); | 452 std::string(), value->DeepCopy()); |
453 | 453 |
454 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). | 454 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). |
455 { | 455 { |
456 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( | 456 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { | 498 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { |
499 sync_preferences::TestingPrefServiceSyncable prefs; | 499 sync_preferences::TestingPrefServiceSyncable prefs; |
500 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 500 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
501 | 501 |
502 ContentSettingsPattern pattern = | 502 ContentSettingsPattern pattern = |
503 ContentSettingsPattern::FromString("google.com"); | 503 ContentSettingsPattern::FromString("google.com"); |
504 ContentSettingsPattern wildcard = | 504 ContentSettingsPattern wildcard = |
505 ContentSettingsPattern::FromString("*"); | 505 ContentSettingsPattern::FromString("*"); |
506 std::unique_ptr<base::Value> value( | 506 std::unique_ptr<base::Value> value( |
507 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | 507 new base::Value(CONTENT_SETTING_ALLOW)); |
508 ResourceIdentifier res_id("abcde"); | 508 ResourceIdentifier res_id("abcde"); |
509 | 509 |
510 PrefProvider provider(&prefs, false); | 510 PrefProvider provider(&prefs, false); |
511 | 511 |
512 // Non-empty pattern, syncable, empty resource identifier. | 512 // Non-empty pattern, syncable, empty resource identifier. |
513 provider.SetWebsiteSetting(pattern, wildcard, | 513 provider.SetWebsiteSetting(pattern, wildcard, |
514 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 514 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
515 ResourceIdentifier(), value->DeepCopy()); | 515 ResourceIdentifier(), value->DeepCopy()); |
516 | 516 |
517 // Non-empty pattern, non-syncable, empty resource identifier. | 517 // Non-empty pattern, non-syncable, empty resource identifier. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 for (const char* pref : nonempty_prefs) { | 567 for (const char* pref : nonempty_prefs) { |
568 DictionaryPrefUpdate update(&prefs, pref); | 568 DictionaryPrefUpdate update(&prefs, pref); |
569 const base::DictionaryValue* dictionary = update.Get(); | 569 const base::DictionaryValue* dictionary = update.Get(); |
570 EXPECT_EQ(1u, dictionary->size()); | 570 EXPECT_EQ(1u, dictionary->size()); |
571 } | 571 } |
572 | 572 |
573 provider.ShutdownOnUIThread(); | 573 provider.ShutdownOnUIThread(); |
574 } | 574 } |
575 | 575 |
576 } // namespace content_settings | 576 } // namespace content_settings |
OLD | NEW |