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

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

Issue 1252073002: Move pref names and default value into WebsiteSettingsInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@website-settings-registry-simple
Patch Set: Created 5 years, 4 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 "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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/prefs/pref_service_mock_factory.h" 22 #include "chrome/browser/prefs/pref_service_mock_factory.h"
23 #include "chrome/browser/prefs/pref_service_syncable.h" 23 #include "chrome/browser/prefs/pref_service_syncable.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "chrome/test/base/testing_pref_service_syncable.h" 27 #include "chrome/test/base/testing_pref_service_syncable.h"
28 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
29 #include "components/content_settings/core/browser/content_settings_pref.h" 29 #include "components/content_settings/core/browser/content_settings_pref.h"
30 #include "components/content_settings/core/browser/content_settings_rule.h" 30 #include "components/content_settings/core/browser/content_settings_rule.h"
31 #include "components/content_settings/core/browser/content_settings_utils.h" 31 #include "components/content_settings/core/browser/content_settings_utils.h"
32 #include "components/content_settings/core/browser/website_settings_info.h"
33 #include "components/content_settings/core/browser/website_settings_registry.h"
32 #include "components/content_settings/core/test/content_settings_test_utils.h" 34 #include "components/content_settings/core/test/content_settings_test_utils.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 35 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "content/public/test/test_browser_thread_bundle.h" 36 #include "content/public/test/test_browser_thread_bundle.h"
35 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
36 #include "url/gurl.h" 38 #include "url/gurl.h"
37 39
38 using ::testing::_; 40 using ::testing::_;
39 41
40 namespace content_settings { 42 namespace content_settings {
41 43
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 class PrefProviderTest : public testing::Test { 99 class PrefProviderTest : public testing::Test {
98 content::TestBrowserThreadBundle thread_bundle_; 100 content::TestBrowserThreadBundle thread_bundle_;
99 }; 101 };
100 102
101 TEST_F(PrefProviderTest, Observer) { 103 TEST_F(PrefProviderTest, Observer) {
102 TestingProfile profile; 104 TestingProfile profile;
103 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false); 105 PrefProvider pref_content_settings_provider(profile.GetPrefs(), false);
104 106
105 ContentSettingsPattern pattern = 107 ContentSettingsPattern pattern =
106 ContentSettingsPattern::FromString("[*.]example.com"); 108 ContentSettingsPattern::FromString("[*.]example.com");
107 content_settings::MockObserver mock_observer; 109 MockObserver mock_observer;
108 EXPECT_CALL(mock_observer, 110 EXPECT_CALL(mock_observer,
109 OnContentSettingChanged(pattern, 111 OnContentSettingChanged(pattern,
110 ContentSettingsPattern::Wildcard(), 112 ContentSettingsPattern::Wildcard(),
111 CONTENT_SETTINGS_TYPE_IMAGES, 113 CONTENT_SETTINGS_TYPE_IMAGES,
112 "")); 114 ""));
113 115
114 pref_content_settings_provider.AddObserver(&mock_observer); 116 pref_content_settings_provider.AddObserver(&mock_observer);
115 117
116 pref_content_settings_provider.SetWebsiteSetting( 118 pref_content_settings_provider.SetWebsiteSetting(
117 pattern, 119 pattern,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 std::string(), 179 std::string(),
178 false)); 180 false));
179 // And also in the OTR version. 181 // And also in the OTR version.
180 EXPECT_EQ(CONTENT_SETTING_ALLOW, 182 EXPECT_EQ(CONTENT_SETTING_ALLOW,
181 GetContentSetting(&pref_content_settings_provider_incognito, 183 GetContentSetting(&pref_content_settings_provider_incognito,
182 host, 184 host,
183 host, 185 host,
184 CONTENT_SETTINGS_TYPE_IMAGES, 186 CONTENT_SETTINGS_TYPE_IMAGES,
185 std::string(), 187 std::string(),
186 false)); 188 false));
189 const WebsiteSettingsInfo* info =
190 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES);
187 // But the value should not be overridden in the OTR user prefs accidentally. 191 // But the value should not be overridden in the OTR user prefs accidentally.
188 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay( 192 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
189 prefs::kContentSettingsImagesPatternPairs));
190 193
191 pref_content_settings_provider.ShutdownOnUIThread(); 194 pref_content_settings_provider.ShutdownOnUIThread();
192 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 195 pref_content_settings_provider_incognito.ShutdownOnUIThread();
193 } 196 }
194 197
195 TEST_F(PrefProviderTest, GetContentSettingsValue) { 198 TEST_F(PrefProviderTest, GetContentSettingsValue) {
196 TestingProfile testing_profile; 199 TestingProfile testing_profile;
197 PrefProvider provider(testing_profile.GetPrefs(), false); 200 PrefProvider provider(testing_profile.GetPrefs(), false);
198 201
199 GURL primary_url("http://example.com/"); 202 GURL primary_url("http://example.com/");
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // http://crosbug.com/17760 418 // http://crosbug.com/17760
416 TEST_F(PrefProviderTest, Deadlock) { 419 TEST_F(PrefProviderTest, Deadlock) {
417 TestingPrefServiceSyncable prefs; 420 TestingPrefServiceSyncable prefs;
418 PrefProvider::RegisterProfilePrefs(prefs.registry()); 421 PrefProvider::RegisterProfilePrefs(prefs.registry());
419 422
420 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 423 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
421 // and writes the preference. When the preference is written, a notification 424 // and writes the preference. When the preference is written, a notification
422 // is sent, and this used to happen when |PrefProvider| was still holding its 425 // is sent, and this used to happen when |PrefProvider| was still holding its
423 // lock. 426 // lock.
424 427
428 const WebsiteSettingsInfo* info =
429 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES);
425 PrefProvider provider(&prefs, false); 430 PrefProvider provider(&prefs, false);
426 DeadlockCheckerObserver observer(&prefs, &provider); 431 DeadlockCheckerObserver observer(&prefs, &provider);
427 { 432 {
428 DictionaryPrefUpdate update(&prefs, 433 DictionaryPrefUpdate update(&prefs, info->pref_name());
429 prefs::kContentSettingsImagesPatternPairs);
430 base::DictionaryValue* mutable_settings = update.Get(); 434 base::DictionaryValue* mutable_settings = update.Get();
431 mutable_settings->SetWithoutPathExpansion("www.example.com,*", 435 mutable_settings->SetWithoutPathExpansion("www.example.com,*",
432 new base::DictionaryValue()); 436 new base::DictionaryValue());
433 } 437 }
434 EXPECT_TRUE(observer.notification_received()); 438 EXPECT_TRUE(observer.notification_received());
435 439
436 provider.ShutdownOnUIThread(); 440 provider.ShutdownOnUIThread();
437 } 441 }
438 442
439 TEST_F(PrefProviderTest, LastUsage) { 443 TEST_F(PrefProviderTest, LastUsage) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 579
576 // Non-empty pattern, non-syncable, empty resource identifier. 580 // Non-empty pattern, non-syncable, empty resource identifier.
577 provider.SetWebsiteSetting(pattern, wildcard, 581 provider.SetWebsiteSetting(pattern, wildcard,
578 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 582 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
579 ResourceIdentifier(), value->DeepCopy()); 583 ResourceIdentifier(), value->DeepCopy());
580 584
581 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES); 585 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_IMAGES);
582 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION); 586 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_GEOLOCATION);
583 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS); 587 provider.ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_PLUGINS);
584 588
589 WebsiteSettingsRegistry* registry = WebsiteSettingsRegistry::GetInstance();
585 // Test that the preferences for images, geolocation and plugins are empty. 590 // Test that the preferences for images, geolocation and plugins are empty.
586 const char* empty_prefs[] = { 591 const char* empty_prefs[] = {
587 prefs::kContentSettingsImagesPatternPairs, 592 registry->Get(CONTENT_SETTINGS_TYPE_IMAGES)->pref_name().c_str(),
588 prefs::kContentSettingsGeolocationPatternPairs, 593 registry->Get(CONTENT_SETTINGS_TYPE_GEOLOCATION)->pref_name().c_str(),
589 prefs::kContentSettingsPluginsPatternPairs 594 registry->Get(CONTENT_SETTINGS_TYPE_PLUGINS)->pref_name().c_str(),
590 }; 595 };
591 596
592 for (const char* pref : empty_prefs) { 597 for (const char* pref : empty_prefs) {
593 DictionaryPrefUpdate update(&prefs, pref); 598 DictionaryPrefUpdate update(&prefs, pref);
594 const base::DictionaryValue* dictionary = update.Get(); 599 const base::DictionaryValue* dictionary = update.Get();
595 EXPECT_TRUE(dictionary->empty()); 600 EXPECT_TRUE(dictionary->empty());
596 } 601 }
597 602
598 // Test that the preferences for cookies and notifications are not empty. 603 // Test that the preferences for cookies and notifications are not empty.
599 const char* nonempty_prefs[] = { 604 const char* nonempty_prefs[] = {
600 prefs::kContentSettingsCookiesPatternPairs, 605 registry->Get(CONTENT_SETTINGS_TYPE_COOKIES)->pref_name().c_str(),
601 prefs::kContentSettingsNotificationsPatternPairs 606 registry->Get(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)->pref_name().c_str(),
602 }; 607 };
603 608
604 for (const char* pref : nonempty_prefs) { 609 for (const char* pref : nonempty_prefs) {
605 DictionaryPrefUpdate update(&prefs, pref); 610 DictionaryPrefUpdate update(&prefs, pref);
606 const base::DictionaryValue* dictionary = update.Get(); 611 const base::DictionaryValue* dictionary = update.Get();
607 EXPECT_EQ(1u, dictionary->size()); 612 EXPECT_EQ(1u, dictionary->size());
608 } 613 }
609 614
610 provider.ShutdownOnUIThread(); 615 provider.ShutdownOnUIThread();
611 } 616 }
612 617
613 } // namespace content_settings 618 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698