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

Unified Diff: chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc

Issue 5398001: Allow default desktop content settings to be managed via policy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove Cocoa UI-changes Created 10 years 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 side-by-side diff with in-line comments
Download patch
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..0177f0f4fd15b16441fb93cd60c50787c2e2bbd5 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,41 @@
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->GetContentSetting(GURL("http://random-hostname.com/"),
+ GURL("http://foo.random-hostname.com/"));
+ }
+
+ GeolocationContentSettingsMap* last_notifier;
+ ContentSettingsPattern last_pattern;
+ bool last_update_all;
+ bool last_update_all_types;
+ int counter;
+ ContentSettingsType last_type;
+
+ private:
+ NotificationRegistrar registrar_;
+};
+
class GeolocationContentSettingsMapTests : public testing::Test {
public:
GeolocationContentSettingsMapTests()
@@ -241,4 +279,32 @@ TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) {
GURL("http://b/")));
}
+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());
+}
+
} // namespace
« no previous file with comments | « chrome/browser/geolocation/geolocation_content_settings_map.cc ('k') | chrome/browser/gtk/options/content_filter_page_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698