diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 02:36:25 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 02:36:25 +0000 |
commit | 79580c6f2f13f43b4735b7e982570fbe779a40ea (patch) | |
tree | aa96dcad2a8614c8083acfa482da2ae650a06030 /chrome/browser/host_content_settings_map_unittest.cc | |
parent | cabe39c43a98b6b635951d5cb3649e061e36ea21 (diff) | |
download | chromium_src-79580c6f2f13f43b4735b7e982570fbe779a40ea.zip chromium_src-79580c6f2f13f43b4735b7e982570fbe779a40ea.tar.gz chromium_src-79580c6f2f13f43b4735b7e982570fbe779a40ea.tar.bz2 |
Send a message to the renderers when content settings change.
BUG=32719
TEST=none
Review URL: http://codereview.chromium.org/551225
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/host_content_settings_map_unittest.cc')
-rw-r--r-- | chrome/browser/host_content_settings_map_unittest.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/chrome/browser/host_content_settings_map_unittest.cc b/chrome/browser/host_content_settings_map_unittest.cc index c4b2f86..dade37c 100644 --- a/chrome/browser/host_content_settings_map_unittest.cc +++ b/chrome/browser/host_content_settings_map_unittest.cc @@ -4,6 +4,8 @@ #include "chrome/browser/host_content_settings_map.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" @@ -19,6 +21,36 @@ bool SettingsEqual(const ContentSettings& settings1, return true; } +class StubSettingsObserver : public NotificationObserver { + public: + StubSettingsObserver() + : last_notifier(NULL), counter(0) { + registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, + NotificationService::AllSources()); + } + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + ++counter; + Source<HostContentSettingsMap> content_settings(source); + Details<HostContentSettingsMap::ContentSettingsDetails> + settings_details(details); + last_notifier = content_settings.ptr(); + last_host = settings_details.ptr()->host(); + // This checks that calling a Get function from an observer doesn't + // deadlock. + last_notifier->GetContentSettings("random-hostname"); + } + + HostContentSettingsMap* last_notifier; + std::string last_host; + int counter; + + private: + NotificationRegistrar registrar_; +}; + class HostContentSettingsMapTest : public testing::Test { public: HostContentSettingsMapTest() @@ -137,4 +169,35 @@ TEST_F(HostContentSettingsMapTest, DefaultValues) { EXPECT_EQ(1U, host_settings.size()); } +TEST_F(HostContentSettingsMapTest, Observer) { + TestingProfile profile; + HostContentSettingsMap* host_content_settings_map = + profile.GetHostContentSettingsMap(); + StubSettingsObserver observer; + + std::string host("example.com"); + host_content_settings_map->SetContentSetting(host, + CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_ALLOW); + EXPECT_EQ(host_content_settings_map, observer.last_notifier); + EXPECT_EQ(host, observer.last_host); + EXPECT_EQ(1, observer.counter); + + host_content_settings_map->ClearSettingsForOneType( + CONTENT_SETTINGS_TYPE_IMAGES); + EXPECT_EQ(host_content_settings_map, observer.last_notifier); + EXPECT_EQ(std::string(), observer.last_host); + EXPECT_EQ(2, observer.counter); + + host_content_settings_map->ResetToDefaults(); + EXPECT_EQ(host_content_settings_map, observer.last_notifier); + EXPECT_EQ(std::string(), observer.last_host); + EXPECT_EQ(3, observer.counter); + + host_content_settings_map->SetDefaultContentSetting( + CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); + EXPECT_EQ(host_content_settings_map, observer.last_notifier); + EXPECT_EQ(std::string(), observer.last_host); + EXPECT_EQ(4, observer.counter); +} + } // namespace |