Chromium Code Reviews| Index: chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
| diff --git a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
| index 2ed941d85999e141665657749686182625b85783..80574dcd705af0e586025d735f6c5d80d2292a94 100644 |
| --- a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
| +++ b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
| @@ -6,7 +6,10 @@ |
| #include "base/message_loop.h" |
| #include "chrome/browser/browser_thread.h" |
| +#include "chrome/browser/content_settings/content_settings_details.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/common/notification_registrar.h" |
| +#include "chrome/common/notification_service.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -14,6 +17,42 @@ |
| namespace { |
| +class StubSettingsObserver : public NotificationObserver { |
| + public: |
| + StubSettingsObserver() : last_notifier(NULL), counter(0) { |
| + registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED, |
| + NotificationService::AllSources()); |
| + } |
| + |
| + virtual void Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + ++counter; |
| + Source<GeolocationContentSettingsMap> content_settings(source); |
| + Details<ContentSettingsDetails> settings_details(details); |
| + last_notifier = content_settings.ptr(); |
| + last_pattern = settings_details.ptr()->pattern(); |
| + last_update_all = settings_details.ptr()->update_all(); |
| + last_update_all_types = settings_details.ptr()->update_all_types(); |
| + last_type = settings_details.ptr()->type(); |
| + // This checks that calling a Get function from an observer doesn't |
| + // deadlock. |
| + last_notifier->GetContentSettings(GURL("http://random-hostname.com/")); |
|
jochen (gone - plz use gerrit)
2010/12/15 14:02:11
i think that doesn't work
markusheintz_
2010/12/15 14:08:35
Already fixed.
|
| + } |
| + |
| + GeolocationContentSettingsMap* last_notifier; |
| + ContentSettingsPattern last_pattern; |
| + bool last_update_all; |
| + bool last_update_all_types; |
| + int counter; |
| + ContentSettingsType last_type; |
| + |
| + private: |
| + NotificationRegistrar registrar_; |
| +}; |
| + |
| +} // namespace |
| + |
| class GeolocationContentSettingsMapTests : public testing::Test { |
| public: |
| GeolocationContentSettingsMapTests() |
| @@ -241,4 +280,30 @@ TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) { |
| GURL("http://b/"))); |
| } |
| -} // namespace |
| +TEST_F(GeolocationContentSettingsMapTests, Observe) { |
| + TestingProfile profile; |
| + GeolocationContentSettingsMap* map = |
| + profile.GetGeolocationContentSettingsMap(); |
| + StubSettingsObserver observer; |
| + |
| + EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting()); |
| + |
| + // Test if a CONTENT_SETTING_CHANGE notification is sent after the geolocation |
| + // default content setting was changed through calling the |
| + // SetDefaultContentSetting method. |
| + map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); |
| + EXPECT_EQ(map, observer.last_notifier); |
| + EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| + EXPECT_EQ(1, observer.counter); |
| + |
| + |
| + // Test if a CONTENT_SETTING_CHANGE notification is sent after the preference |
| + // GeolocationDefaultContentSetting was changed. |
| + PrefService* prefs = profile.GetPrefs(); |
| + prefs->SetInteger(prefs::kGeolocationDefaultContentSetting, |
| + CONTENT_SETTING_ALLOW); |
| + EXPECT_EQ(2, observer.counter); |
| + EXPECT_EQ(map, observer.last_notifier); |
| + EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting()); |
| +} |