| 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 c5514ce461204ce88fa81d57a930c9bfd9474497..74a36266242d21adac5cca65534cb2c27a665c81 100644
|
| --- a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
|
| +++ b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc
|
| @@ -12,46 +12,51 @@
|
| #include "content/browser/browser_thread.h"
|
| #include "content/common/notification_registrar.h"
|
| #include "content/common/notification_service.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +using ::testing::_;
|
|
|
| namespace {
|
|
|
| -class StubSettingsObserver : public NotificationObserver {
|
| +class MockGeolocationSettingsObserver : public NotificationObserver {
|
| public:
|
| - StubSettingsObserver() : last_notifier(NULL), counter(0) {
|
| - registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED,
|
| - NotificationService::AllSources());
|
| - }
|
| + MockGeolocationSettingsObserver();
|
|
|
| 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->GetContentSetting(GURL("http://random-hostname.com/"),
|
| - GURL("http://foo.random-hostname.com/"));
|
| - }
|
| + const NotificationDetails& details);
|
|
|
| - GeolocationContentSettingsMap* last_notifier;
|
| - ContentSettingsPattern last_pattern;
|
| - bool last_update_all;
|
| - bool last_update_all_types;
|
| - int counter;
|
| - ContentSettingsType last_type;
|
| + MOCK_METHOD2(OnContentSettingsChanged,
|
| + void(GeolocationContentSettingsMap*,
|
| + ContentSettingsType));
|
|
|
| private:
|
| NotificationRegistrar registrar_;
|
| };
|
|
|
| +MockGeolocationSettingsObserver::MockGeolocationSettingsObserver() {
|
| + registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED,
|
| + NotificationService::AllSources());
|
| +}
|
| +
|
| +void MockGeolocationSettingsObserver::Observe(
|
| + NotificationType type,
|
| + const NotificationSource& source,
|
| + const NotificationDetails& details) {
|
| + GeolocationContentSettingsMap* map =
|
| + Source<GeolocationContentSettingsMap>(source).ptr();
|
| + ContentSettingsDetails* settings_details =
|
| + Details<ContentSettingsDetails>(details).ptr();
|
| + OnContentSettingsChanged(map,
|
| + settings_details->type());
|
| + // This checks that calling a Get function from an observer doesn't
|
| + // deadlock.
|
| + // TODO(bauerb): Move into expectation setup.
|
| + map->GetContentSetting(GURL("http://random-hostname.com/"),
|
| + GURL("http://foo.random-hostname.com/"));
|
| +}
|
| +
|
| class GeolocationContentSettingsMapTests : public testing::Test {
|
| public:
|
| GeolocationContentSettingsMapTests()
|
| @@ -285,27 +290,27 @@ TEST_F(GeolocationContentSettingsMapTests, Observe) {
|
| TestingProfile profile;
|
| GeolocationContentSettingsMap* map =
|
| profile.GetGeolocationContentSettingsMap();
|
| - StubSettingsObserver observer;
|
| + MockGeolocationSettingsObserver 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
|
| + // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
|
| + // the geolocation default content setting was changed through calling the
|
| // SetDefaultContentSetting method.
|
| + EXPECT_CALL(
|
| + observer,
|
| + OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
|
| 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);
|
| -
|
| + ::testing::Mock::VerifyAndClearExpectations(&observer);
|
|
|
| - // Test if a CONTENT_SETTING_CHANGE notification is sent after the preference
|
| - // GeolocationDefaultContentSetting was changed.
|
| + // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
|
| + // the preference kGeolocationDefaultContentSetting was changed.
|
| PrefService* prefs = profile.GetPrefs();
|
| + EXPECT_CALL(
|
| + observer,
|
| + OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
|
| 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());
|
| }
|
|
|
|
|