Vectorize sad tab image.
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_pref_provider_unittest.cc
blobfee5ea095c977bbc20418b4ded7dc7268c3e8cfe
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
3 // found in the LICENSE file.
5 #include "components/content_settings/core/browser/content_settings_pref_provider.h"
7 #include "base/auto_reset.h"
8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/default_pref_store.h"
12 #include "base/prefs/overlay_user_pref_store.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/prefs/testing_pref_store.h"
17 #include "base/test/simple_test_clock.h"
18 #include "base/threading/platform_thread.h"
19 #include "base/values.h"
20 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
21 #include "chrome/browser/prefs/browser_prefs.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "components/content_settings/core/browser/content_settings_pref.h"
27 #include "components/content_settings/core/browser/content_settings_registry.h"
28 #include "components/content_settings/core/browser/content_settings_rule.h"
29 #include "components/content_settings/core/browser/website_settings_info.h"
30 #include "components/content_settings/core/browser/website_settings_registry.h"
31 #include "components/content_settings/core/common/content_settings_pattern.h"
32 #include "components/content_settings/core/test/content_settings_test_utils.h"
33 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/syncable_prefs/pref_service_mock_factory.h"
35 #include "components/syncable_prefs/pref_service_syncable.h"
36 #include "components/syncable_prefs/testing_pref_service_syncable.h"
37 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "url/gurl.h"
41 using ::testing::_;
43 namespace content_settings {
45 class DeadlockCheckerThread : public base::PlatformThread::Delegate {
46 public:
47 explicit DeadlockCheckerThread(const ContentSettingsPref* pref)
48 : pref_(pref) {}
50 void ThreadMain() override {
51 EXPECT_TRUE(pref_->TryLockForTesting());
53 private:
54 const ContentSettingsPref* pref_;
55 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread);
58 // A helper for observing an preference changes and testing whether
59 // |PrefProvider| holds a lock when the preferences change.
60 class DeadlockCheckerObserver {
61 public:
62 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or
63 // |provider|.
64 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider)
65 : provider_(provider),
66 notification_received_(false) {
67 pref_change_registrar_.Init(prefs);
68 for (ContentSettingsPref* pref : provider_->content_settings_prefs_) {
69 pref_change_registrar_.Add(
70 pref->pref_name_,
71 base::Bind(
72 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged,
73 base::Unretained(this), base::Unretained(pref)));
76 virtual ~DeadlockCheckerObserver() {}
78 bool notification_received() const {
79 return notification_received_;
82 private:
83 void OnContentSettingsPatternPairsChanged(const ContentSettingsPref* pref) {
84 // Check whether |provider_| holds its lock. For this, we need a
85 // separate thread.
86 DeadlockCheckerThread thread(pref);
87 base::PlatformThreadHandle handle;
88 ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle));
89 base::PlatformThread::Join(handle);
90 notification_received_ = true;
93 PrefProvider* provider_;
94 PrefChangeRegistrar pref_change_registrar_;
95 bool notification_received_;
96 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerObserver);
99 class PrefProviderTest : public testing::Test {
100 public:
101 PrefProviderTest() {
102 // Ensure all content settings are initialized.
103 ContentSettingsRegistry::GetInstance();
106 private:
107 content::TestBrowserThreadBundle thread_bundle_;
110 TEST_F(PrefProviderTest, Observer) {
111 TestingProfile profile;
112 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false);
114 ContentSettingsPattern pattern =
115 ContentSettingsPattern::FromString("[*.]example.com");
116 MockObserver mock_observer;
117 EXPECT_CALL(mock_observer,
118 OnContentSettingChanged(pattern,
119 ContentSettingsPattern::Wildcard(),
120 CONTENT_SETTINGS_TYPE_IMAGES,
121 ""));
123 pref_content_settings_provider.AddObserver(&mock_observer);
125 pref_content_settings_provider.SetWebsiteSetting(
126 pattern,
127 ContentSettingsPattern::Wildcard(),
128 CONTENT_SETTINGS_TYPE_IMAGES,
129 std::string(),
130 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
132 pref_content_settings_provider.ShutdownOnUIThread();
135 // Test for regression in which the PrefProvider modified the user pref store
136 // of the OTR unintentionally: http://crbug.com/74466.
137 TEST_F(PrefProviderTest, Incognito) {
138 PersistentPrefStore* user_prefs = new TestingPrefStore();
139 OverlayUserPrefStore* otr_user_prefs =
140 new OverlayUserPrefStore(user_prefs);
142 syncable_prefs::PrefServiceMockFactory factory;
143 factory.set_user_prefs(make_scoped_refptr(user_prefs));
144 scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
145 new user_prefs::PrefRegistrySyncable);
146 syncable_prefs::PrefServiceSyncable* regular_prefs =
147 factory.CreateSyncable(registry.get()).release();
149 chrome::RegisterUserProfilePrefs(registry.get());
151 syncable_prefs::PrefServiceMockFactory otr_factory;
152 otr_factory.set_user_prefs(make_scoped_refptr(otr_user_prefs));
153 scoped_refptr<user_prefs::PrefRegistrySyncable> otr_registry(
154 new user_prefs::PrefRegistrySyncable);
155 syncable_prefs::PrefServiceSyncable* otr_prefs =
156 otr_factory.CreateSyncable(otr_registry.get()).release();
158 chrome::RegisterUserProfilePrefs(otr_registry.get());
160 TestingProfile::Builder profile_builder;
161 profile_builder.SetPrefService(make_scoped_ptr(regular_prefs));
162 scoped_ptr<TestingProfile> profile = profile_builder.Build();
164 TestingProfile::Builder otr_profile_builder;
165 otr_profile_builder.SetPrefService(make_scoped_ptr(otr_prefs));
166 otr_profile_builder.BuildIncognito(profile.get());
168 PrefProvider pref_content_settings_provider(regular_prefs, false);
169 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
170 ContentSettingsPattern pattern =
171 ContentSettingsPattern::FromString("[*.]example.com");
172 pref_content_settings_provider.SetWebsiteSetting(
173 pattern,
174 pattern,
175 CONTENT_SETTINGS_TYPE_IMAGES,
176 std::string(),
177 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
179 GURL host("http://example.com/");
180 // The value should of course be visible in the regular PrefProvider.
181 EXPECT_EQ(CONTENT_SETTING_ALLOW,
182 GetContentSetting(&pref_content_settings_provider,
183 host,
184 host,
185 CONTENT_SETTINGS_TYPE_IMAGES,
186 std::string(),
187 false));
188 // And also in the OTR version.
189 EXPECT_EQ(CONTENT_SETTING_ALLOW,
190 GetContentSetting(&pref_content_settings_provider_incognito,
191 host,
192 host,
193 CONTENT_SETTINGS_TYPE_IMAGES,
194 std::string(),
195 false));
196 const WebsiteSettingsInfo* info =
197 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES);
198 // But the value should not be overridden in the OTR user prefs accidentally.
199 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
201 pref_content_settings_provider.ShutdownOnUIThread();
202 pref_content_settings_provider_incognito.ShutdownOnUIThread();
205 TEST_F(PrefProviderTest, GetContentSettingsValue) {
206 TestingProfile testing_profile;
207 PrefProvider provider(testing_profile.GetPrefs(), false);
209 GURL primary_url("http://example.com/");
210 ContentSettingsPattern primary_pattern =
211 ContentSettingsPattern::FromString("[*.]example.com");
213 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
214 GetContentSetting(&provider,
215 primary_url,
216 primary_url,
217 CONTENT_SETTINGS_TYPE_IMAGES,
218 std::string(),
219 false));
221 EXPECT_EQ(NULL,
222 GetContentSettingValue(&provider,
223 primary_url,
224 primary_url,
225 CONTENT_SETTINGS_TYPE_IMAGES,
226 std::string(),
227 false));
229 provider.SetWebsiteSetting(primary_pattern,
230 primary_pattern,
231 CONTENT_SETTINGS_TYPE_IMAGES,
232 std::string(),
233 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
234 EXPECT_EQ(CONTENT_SETTING_BLOCK,
235 GetContentSetting(&provider,
236 primary_url,
237 primary_url,
238 CONTENT_SETTINGS_TYPE_IMAGES,
239 std::string(),
240 false));
241 scoped_ptr<base::Value> value_ptr(
242 GetContentSettingValue(&provider,
243 primary_url,
244 primary_url,
245 CONTENT_SETTINGS_TYPE_IMAGES,
246 std::string(),
247 false));
248 int int_value = -1;
249 value_ptr->GetAsInteger(&int_value);
250 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
252 provider.SetWebsiteSetting(primary_pattern,
253 primary_pattern,
254 CONTENT_SETTINGS_TYPE_IMAGES,
255 std::string(),
256 NULL);
257 EXPECT_EQ(NULL,
258 GetContentSettingValue(&provider,
259 primary_url,
260 primary_url,
261 CONTENT_SETTINGS_TYPE_IMAGES,
262 std::string(),
263 false));
264 provider.ShutdownOnUIThread();
267 TEST_F(PrefProviderTest, Patterns) {
268 TestingProfile testing_profile;
269 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
270 false);
272 GURL host1("http://example.com/");
273 GURL host2("http://www.example.com/");
274 GURL host3("http://example.org/");
275 GURL host4("file:///tmp/test.html");
276 ContentSettingsPattern pattern1 =
277 ContentSettingsPattern::FromString("[*.]example.com");
278 ContentSettingsPattern pattern2 =
279 ContentSettingsPattern::FromString("example.org");
280 ContentSettingsPattern pattern3 =
281 ContentSettingsPattern::FromString("file:///tmp/test.html");
283 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
284 GetContentSetting(&pref_content_settings_provider,
285 host1,
286 host1,
287 CONTENT_SETTINGS_TYPE_IMAGES,
288 std::string(),
289 false));
290 pref_content_settings_provider.SetWebsiteSetting(
291 pattern1,
292 pattern1,
293 CONTENT_SETTINGS_TYPE_IMAGES,
294 std::string(),
295 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
296 EXPECT_EQ(CONTENT_SETTING_BLOCK,
297 GetContentSetting(&pref_content_settings_provider,
298 host1,
299 host1,
300 CONTENT_SETTINGS_TYPE_IMAGES,
301 std::string(),
302 false));
303 EXPECT_EQ(CONTENT_SETTING_BLOCK,
304 GetContentSetting(&pref_content_settings_provider,
305 host2,
306 host2,
307 CONTENT_SETTINGS_TYPE_IMAGES,
308 std::string(),
309 false));
311 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
312 GetContentSetting(&pref_content_settings_provider,
313 host3,
314 host3,
315 CONTENT_SETTINGS_TYPE_IMAGES,
316 std::string(),
317 false));
318 pref_content_settings_provider.SetWebsiteSetting(
319 pattern2,
320 pattern2,
321 CONTENT_SETTINGS_TYPE_IMAGES,
322 std::string(),
323 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
324 EXPECT_EQ(CONTENT_SETTING_BLOCK,
325 GetContentSetting(&pref_content_settings_provider,
326 host3,
327 host3,
328 CONTENT_SETTINGS_TYPE_IMAGES,
329 std::string(),
330 false));
332 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
333 GetContentSetting(&pref_content_settings_provider,
334 host4,
335 host4,
336 CONTENT_SETTINGS_TYPE_IMAGES,
337 std::string(),
338 false));
339 pref_content_settings_provider.SetWebsiteSetting(
340 pattern3,
341 pattern3,
342 CONTENT_SETTINGS_TYPE_IMAGES,
343 std::string(),
344 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
345 EXPECT_EQ(CONTENT_SETTING_BLOCK,
346 GetContentSetting(&pref_content_settings_provider,
347 host4,
348 host4,
349 CONTENT_SETTINGS_TYPE_IMAGES,
350 std::string(),
351 false));
353 pref_content_settings_provider.ShutdownOnUIThread();
356 TEST_F(PrefProviderTest, ResourceIdentifier) {
357 TestingProfile testing_profile;
358 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
359 false);
361 GURL host("http://example.com/");
362 ContentSettingsPattern pattern =
363 ContentSettingsPattern::FromString("[*.]example.com");
364 std::string resource1("someplugin");
365 std::string resource2("otherplugin");
367 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
368 GetContentSetting(
369 &pref_content_settings_provider,
370 host, host, CONTENT_SETTINGS_TYPE_PLUGINS,
371 resource1, false));
372 pref_content_settings_provider.SetWebsiteSetting(
373 pattern,
374 pattern,
375 CONTENT_SETTINGS_TYPE_PLUGINS,
376 resource1,
377 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
378 EXPECT_EQ(CONTENT_SETTING_BLOCK,
379 GetContentSetting(
380 &pref_content_settings_provider,
381 host, host, CONTENT_SETTINGS_TYPE_PLUGINS,
382 resource1, false));
383 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
384 GetContentSetting(
385 &pref_content_settings_provider,
386 host, host, CONTENT_SETTINGS_TYPE_PLUGINS,
387 resource2, false));
389 pref_content_settings_provider.ShutdownOnUIThread();
392 TEST_F(PrefProviderTest, AutoSubmitCertificateContentSetting) {
393 TestingProfile profile;
394 syncable_prefs::TestingPrefServiceSyncable* prefs =
395 profile.GetTestingPrefService();
396 GURL primary_url("https://www.example.com");
397 GURL secondary_url("https://www.sample.com");
399 PrefProvider provider(prefs, false);
401 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
402 GetContentSetting(
403 &provider,
404 primary_url,
405 primary_url,
406 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
407 std::string(),
408 false));
410 provider.SetWebsiteSetting(ContentSettingsPattern::FromURL(primary_url),
411 ContentSettingsPattern::Wildcard(),
412 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
413 std::string(),
414 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
415 EXPECT_EQ(CONTENT_SETTING_ALLOW,
416 GetContentSetting(
417 &provider,
418 primary_url,
419 secondary_url,
420 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
421 std::string(),
422 false));
423 provider.ShutdownOnUIThread();
426 // http://crosbug.com/17760
427 TEST_F(PrefProviderTest, Deadlock) {
428 syncable_prefs::TestingPrefServiceSyncable prefs;
429 PrefProvider::RegisterProfilePrefs(prefs.registry());
431 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
432 // and writes the preference. When the preference is written, a notification
433 // is sent, and this used to happen when |PrefProvider| was still holding its
434 // lock.
436 const WebsiteSettingsInfo* info =
437 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES);
438 PrefProvider provider(&prefs, false);
439 DeadlockCheckerObserver observer(&prefs, &provider);
441 DictionaryPrefUpdate update(&prefs, info->pref_name());
442 base::DictionaryValue* mutable_settings = update.Get();
443 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
444 new base::DictionaryValue());
446 EXPECT_TRUE(observer.notification_received());
448 provider.ShutdownOnUIThread();
451 TEST_F(PrefProviderTest, LastUsage) {
452 TestingProfile testing_profile;
453 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
454 false);
455 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
456 test_clock->SetNow(base::Time::Now());
458 pref_content_settings_provider.SetClockForTesting(
459 scoped_ptr<base::Clock>(test_clock));
460 GURL host("http://example.com/");
461 ContentSettingsPattern pattern =
462 ContentSettingsPattern::FromString("[*.]example.com");
464 base::Time no_usage = pref_content_settings_provider.GetLastUsage(
465 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
466 EXPECT_EQ(no_usage.ToDoubleT(), 0);
468 pref_content_settings_provider.UpdateLastUsage(
469 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
470 base::Time first = pref_content_settings_provider.GetLastUsage(
471 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
473 test_clock->Advance(base::TimeDelta::FromSeconds(10));
475 pref_content_settings_provider.UpdateLastUsage(
476 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
477 base::Time second = pref_content_settings_provider.GetLastUsage(
478 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION);
480 base::TimeDelta delta = second - first;
481 EXPECT_EQ(delta.InSeconds(), 10);
483 pref_content_settings_provider.ShutdownOnUIThread();
486 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
487 syncable_prefs::TestingPrefServiceSyncable prefs;
488 PrefProvider::RegisterProfilePrefs(prefs.registry());
490 ContentSettingsPattern pattern_1 =
491 ContentSettingsPattern::FromString("google.com");
492 ContentSettingsPattern pattern_2 =
493 ContentSettingsPattern::FromString("www.google.com");
494 ContentSettingsPattern wildcard =
495 ContentSettingsPattern::FromString("*");
496 scoped_ptr<base::Value> value(
497 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
499 // Create a normal provider and set a setting.
500 PrefProvider normal_provider(&prefs, false);
501 normal_provider.SetWebsiteSetting(pattern_1,
502 wildcard,
503 CONTENT_SETTINGS_TYPE_IMAGES,
504 std::string(),
505 value->DeepCopy());
507 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1).
509 scoped_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
510 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false));
511 EXPECT_TRUE(it->HasNext());
512 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
513 EXPECT_FALSE(it->HasNext());
516 // Non-OTR provider, OTR iterator has no settings.
518 scoped_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
519 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true));
520 EXPECT_FALSE(it->HasNext());
523 // Create an incognito provider and set a setting.
524 PrefProvider incognito_provider(&prefs, true);
525 incognito_provider.SetWebsiteSetting(pattern_2,
526 wildcard,
527 CONTENT_SETTINGS_TYPE_IMAGES,
528 std::string(),
529 value->DeepCopy());
531 // OTR provider, non-OTR iterator has one setting (pattern 1).
533 scoped_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
534 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false));
535 EXPECT_TRUE(it->HasNext());
536 EXPECT_EQ(pattern_1, it->Next().primary_pattern);
537 EXPECT_FALSE(it->HasNext());
540 // OTR provider, OTR iterator has one setting (pattern 2).
542 scoped_ptr<RuleIterator> it(incognito_provider.GetRuleIterator(
543 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), true));
544 EXPECT_TRUE(it->HasNext());
545 EXPECT_EQ(pattern_2, it->Next().primary_pattern);
546 EXPECT_FALSE(it->HasNext());
549 incognito_provider.ShutdownOnUIThread();
550 normal_provider.ShutdownOnUIThread();
553 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
554 syncable_prefs::TestingPrefServiceSyncable prefs;
555 PrefProvider::RegisterProfilePrefs(prefs.registry());
557 ContentSettingsPattern pattern =
558 ContentSettingsPattern::FromString("google.com");
559 ContentSettingsPattern wildcard =
560 ContentSettingsPattern::FromString("*");
561 scoped_ptr<base::Value> value(
562 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
563 ResourceIdentifier res_id("abcde");
565 PrefProvider provider(&prefs, false);
567 // Non-empty pattern, syncable, empty resource identifier.
568 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_IMAGES,
569 ResourceIdentifier(), value->DeepCopy());
571 // Non-empty pattern, non-syncable, empty resource identifier.
572 provider.SetWebsiteSetting(pattern, wildcard,
573 CONTENT_SETTINGS_TYPE_GEOLOCATION,
574 ResourceIdentifier(), value->DeepCopy());
576 // Non-empty pattern, plugins, non-empty resource identifier.
577 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS,
578 res_id, value->DeepCopy());
580 // Empty pattern, plugins, non-empty resource identifier.
581 provider.SetWebsiteSetting(wildcard, wildcard, CONTENT_SETTINGS_TYPE_PLUGINS,
582 res_id, value->DeepCopy());
584 // Non-empty pattern, syncable, empty resource identifier.
585 provider.SetWebsiteSetting(pattern, wildcard, CONTENT_SETTINGS_TYPE_COOKIES,
586 ResourceIdentifier(), value->DeepCopy());
588 // Non-empty pattern, non-syncable, empty resource identifier.
589 provider.SetWebsiteSetting(pattern, wildcard,
590 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
591 ResourceIdentifier(), value->DeepCopy());
593 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES);
594 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION);
595 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS);
597 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance();
598 // Test that the preferences for images, geolocation and plugins are empty.
599 const char* empty_prefs[] = {
600 registry->Get(CONTENT_SETTINGS_TYPE_IMAGES)->pref_name().c_str(),
601 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(),
602 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(),
605 for (const char* pref : empty_prefs) {
606 DictionaryPrefUpdate update(&prefs, pref);
607 const base::DictionaryValue* dictionary = update.Get();
608 EXPECT_TRUE(dictionary->empty());
611 // Test that the preferences for cookies and notifications are not empty.
612 const char* nonempty_prefs[] = {
613 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(),
614 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(),
617 for (const char* pref : nonempty_prefs) {
618 DictionaryPrefUpdate update(&prefs, pref);
619 const base::DictionaryValue* dictionary = update.Get();
620 EXPECT_EQ(1u, dictionary->size());
623 provider.ShutdownOnUIThread();
626 } // namespace content_settings