diff options
author | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 18:07:20 +0000 |
---|---|---|
committer | csilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 18:07:20 +0000 |
commit | 3d8bea6aecc94233557df4ca1456d255f61169bd (patch) | |
tree | 8eac6923d6872cb6efca749e45c14a477a97f120 | |
parent | 221fbdc510bfa190c5093ed977c87cd99cade23c (diff) | |
download | chromium_src-3d8bea6aecc94233557df4ca1456d255f61169bd.zip chromium_src-3d8bea6aecc94233557df4ca1456d255f61169bd.tar.gz chromium_src-3d8bea6aecc94233557df4ca1456d255f61169bd.tar.bz2 |
Add observers to ContentSettingsDialogController so that the dialog will show
live updates in response to sycronization.
BUG=41335
TEST=Open the 'Content settings' dialog on two separate instances of Chromium
when both are synced to the same account. Change settings on computer A,
settings should auto-update on computer B.
Review URL: http://codereview.chromium.org/2063020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49979 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 349 insertions, 50 deletions
diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 187f7f8..4481637 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -9,6 +9,21 @@ #include "chrome/common/content_settings_types.h" #include "chrome/browser/pref_member.h" +// Index of the "enabled" and "disabled" radio group settings in all tabs except +// for the cookies tab. +const NSInteger kContentSettingsEnabledIndex = 0; +const NSInteger kContentSettingsDisabledIndex = 1; + +// Indices of the various cookie settings in the cookie radio group. +const NSInteger kCookieEnabledIndex = 0; +const NSInteger kCookieAskIndex = 1; +const NSInteger kCookieDisabledIndex = 2; + +// Indices of the various geolocation settings in the geolocation radio group. +const NSInteger kGeolocationEnabledIndex = 0; +const NSInteger kGeolocationAskIndex = 1; +const NSInteger kGeolocationDisabledIndex = 2; + namespace ContentSettingsDialogControllerInternal { class PrefObserverBridge; } @@ -50,3 +65,15 @@ class Profile; - (IBAction)showGeolocationExceptions:(id)sender; @end + +@interface ContentSettingsDialogController (TestingAPI) +// Properties that the radio groups and checkboxes are bound to. +@property(assign, nonatomic) NSInteger cookieSettingIndex; +@property(assign, nonatomic) BOOL blockThirdPartyCookies; +@property(assign, nonatomic) BOOL clearSiteDataOnExit; +@property(assign, nonatomic) NSInteger imagesEnabledIndex; +@property(assign, nonatomic) NSInteger javaScriptEnabledIndex; +@property(assign, nonatomic) NSInteger popupsEnabledIndex; +@property(assign, nonatomic) NSInteger pluginsEnabledIndex; +@property(assign, nonatomic) NSInteger geolocationSettingIndex; +@end diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index 3f792e3c..c0f7e57 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -25,24 +25,9 @@ namespace { -// Index of the "enabled" and "disabled" radio group settings in all tabs except -// for the cookies tab. -const NSInteger kEnabledIndex = 0; -const NSInteger kDisabledIndex = 1; - -// Indices of the various cookie settings in the cookie radio group. -const NSInteger kCookieEnabledIndex = 0; -const NSInteger kCookieAskIndex = 1; -const NSInteger kCookieDisabledIndex = 2; - // Stores the currently visible content settings dialog, if any. ContentSettingsDialogController* g_instance = nil; -// Indices of the various geolocation settings in the geolocation radio group. -const NSInteger kGeolocationEnabledIndex = 0; -const NSInteger kGeolocationAskIndex = 1; -const NSInteger kGeolocationDisabledIndex = 2; - // Walks views in top-down order, wraps each to their current width, and moves // the latter ones down to prevent overlaps. CGFloat VerticallyReflowGroup(NSArray* views) { @@ -77,15 +62,9 @@ CGFloat VerticallyReflowGroup(NSArray* views) { - (void)selectTab:(ContentSettingsType)settingsType; - (void)showExceptionsForType:(ContentSettingsType)settingsType; -// Properties that the radio groups and checkboxes are bound to. -@property(assign, nonatomic) NSInteger cookieSettingIndex; -@property(assign, nonatomic) BOOL blockThirdPartyCookies; -@property(assign, nonatomic) BOOL clearSiteDataOnExit; -@property(assign, nonatomic) NSInteger imagesEnabledIndex; -@property(assign, nonatomic) NSInteger javaScriptEnabledIndex; -@property(assign, nonatomic) NSInteger popupsEnabledIndex; -@property(assign, nonatomic) NSInteger pluginsEnabledIndex; -@property(assign, nonatomic) NSInteger geolocationSettingIndex; +// Callback when preferences are changed. |prefName| is the name of the +// pref that has changed. +- (void)prefChanged:(std::wstring*)prefName; @end @@ -102,25 +81,42 @@ class PrefObserverBridge : public NotificationObserver { virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - std::wstring* pref_name = Details<std::wstring>(details).ptr(); - if (*pref_name == prefs::kClearSiteDataOnExit) { - // Update UI. - [controller_ setClearSiteDataOnExit:[controller_ clearSiteDataOnExit]]; - } + if (!disabled_ && type == NotificationType::PREF_CHANGED) { + [controller_ prefChanged:Details<std::wstring>(details).ptr()]; } } + void SetDisabled(bool disabled) { + disabled_ = disabled; + } + private: ContentSettingsDialogController* controller_; // weak, owns us + bool disabled_; // true if notifications should be ignored. +}; + +// A C++ utility class to disable notifications for PrefsObserverBridge. +// The intended usage is to create on the stack. +class PrefObserverDisabler { + public: + PrefObserverDisabler(PrefObserverBridge *bridge) : bridge_(bridge) { + bridge_->SetDisabled(true); + } + + ~PrefObserverDisabler() { + bridge_->SetDisabled(false); + } + + private: + PrefObserverBridge *bridge_; }; } // ContentSettingsDialogControllerInternal @implementation ContentSettingsDialogController -+(id)showContentSettingsForType:(ContentSettingsType)settingsType - profile:(Profile*)profile { ++ (id)showContentSettingsForType:(ContentSettingsType)settingsType + profile:(Profile*)profile { profile = profile->GetOriginalProfile(); if (!g_instance) g_instance = [[self alloc] initWithProfile:profile]; @@ -157,15 +153,35 @@ class PrefObserverBridge : public NotificationObserver { observer_.reset( new ContentSettingsDialogControllerInternal::PrefObserverBridge(self)); clearSiteDataOnExit_.Init(prefs::kClearSiteDataOnExit, - profile->GetPrefs(), observer_.get()); + profile_->GetPrefs(), observer_.get()); + + // Manually observe notifications for preferences that are grouped in + // the HostContentSettingsMap or GeolocationContentSettingsMap. + PrefService* prefs = profile_->GetPrefs(); + prefs->AddPrefObserver(prefs::kBlockThirdPartyCookies, observer_.get()); + prefs->AddPrefObserver(prefs::kDefaultContentSettings, observer_.get()); + prefs->AddPrefObserver(prefs::kGeolocationDefaultContentSetting, + observer_.get()); // We don't need to observe changes in this value. lastSelectedTab_.Init(prefs::kContentSettingsWindowLastTabIndex, - profile->GetPrefs(), NULL); + profile_->GetPrefs(), NULL); } return self; } +- (void)dealloc { + if (profile_) { + PrefService* prefs = profile_->GetPrefs(); + prefs->RemovePrefObserver(prefs::kBlockThirdPartyCookies, observer_.get()); + prefs->RemovePrefObserver(prefs::kDefaultContentSettings, observer_.get()); + prefs->RemovePrefObserver(prefs::kGeolocationDefaultContentSetting, + observer_.get()); + } + + [super dealloc]; +} + - (void)closeExceptionsSheet { NSWindow* attachedSheet = [[self window] attachedSheet]; if (attachedSheet) { @@ -228,6 +244,8 @@ class PrefObserverBridge : public NotificationObserver { default: NOTREACHED(); } + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_COOKIES, setting); @@ -252,6 +270,8 @@ class PrefObserverBridge : public NotificationObserver { - (void)setBlockThirdPartyCookies:(BOOL)value { HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); settingsMap->SetBlockThirdPartyCookies(value); } @@ -260,7 +280,9 @@ class PrefObserverBridge : public NotificationObserver { } - (void)setClearSiteDataOnExit:(BOOL)value { - return clearSiteDataOnExit_.SetValue(value); + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); + clearSiteDataOnExit_.SetValue(value); } // Shows the cookies controller. @@ -331,8 +353,10 @@ class PrefObserverBridge : public NotificationObserver { } - (void)setImagesEnabledIndex:(NSInteger)value { - ContentSetting setting = value == kEnabledIndex ? + ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_IMAGES, setting); } @@ -342,12 +366,14 @@ class PrefObserverBridge : public NotificationObserver { bool enabled = settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES) == CONTENT_SETTING_ALLOW; - return enabled ? kEnabledIndex : kDisabledIndex; + return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } - (void)setJavaScriptEnabledIndex:(NSInteger)value { - ContentSetting setting = value == kEnabledIndex ? + ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_JAVASCRIPT, setting); } @@ -357,12 +383,14 @@ class PrefObserverBridge : public NotificationObserver { bool enabled = settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT) == CONTENT_SETTING_ALLOW; - return enabled ? kEnabledIndex : kDisabledIndex; + return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } - (void)setPluginsEnabledIndex:(NSInteger)value { - ContentSetting setting = value == kEnabledIndex ? + ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_PLUGINS, setting); } @@ -372,12 +400,14 @@ class PrefObserverBridge : public NotificationObserver { bool enabled = settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS) == CONTENT_SETTING_ALLOW; - return enabled ? kEnabledIndex : kDisabledIndex; + return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } - (void)setPopupsEnabledIndex:(NSInteger)value { - ContentSetting setting = value == kEnabledIndex ? + ContentSetting setting = value == kContentSettingsEnabledIndex ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_POPUPS, setting); } @@ -387,7 +417,7 @@ class PrefObserverBridge : public NotificationObserver { bool enabled = settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW; - return enabled ? kEnabledIndex : kDisabledIndex; + return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; } - (void)setGeolocationSettingIndex:(NSInteger)value { @@ -399,6 +429,8 @@ class PrefObserverBridge : public NotificationObserver { default: NOTREACHED(); } + ContentSettingsDialogControllerInternal::PrefObserverDisabler + disabler(observer_.get()); profile_->GetGeolocationContentSettingsMap()->SetDefaultContentSetting( setting); } @@ -416,4 +448,38 @@ class PrefObserverBridge : public NotificationObserver { } } +// Callback when preferences are changed. |prefName| is the name of the +// pref that has changed and should not be NULL. +- (void)prefChanged:(std::wstring*)prefName { + DCHECK(prefName); + if (!prefName) return; + if (*prefName == prefs::kClearSiteDataOnExit) { + [self willChangeValueForKey:@"clearSiteDataOnExit"]; + [self didChangeValueForKey:@"clearSiteDataOnExit"]; + } + if (*prefName == prefs::kBlockThirdPartyCookies) { + [self willChangeValueForKey:@"blockThirdPartyCookies"]; + [self didChangeValueForKey:@"blockThirdPartyCookies"]; + } + if (*prefName == prefs::kDefaultContentSettings) { + // We don't know exactly which setting has changed, so we'll tickle all + // of the properties that apply to kDefaultContentSettings. This will + // keep the UI up-to-date. + [self willChangeValueForKey:@"cookieSettingIndex"]; + [self didChangeValueForKey:@"cookieSettingIndex"]; + [self willChangeValueForKey:@"imagesEnabledIndex"]; + [self didChangeValueForKey:@"imagesEnabledIndex"]; + [self willChangeValueForKey:@"javaScriptEnabledIndex"]; + [self didChangeValueForKey:@"javaScriptEnabledIndex"]; + [self willChangeValueForKey:@"pluginsEnabledIndex"]; + [self didChangeValueForKey:@"pluginsEnabledIndex"]; + [self willChangeValueForKey:@"popupsEnabledIndex"]; + [self didChangeValueForKey:@"popupsEnabledIndex"]; + } + if (*prefName == prefs::kGeolocationDefaultContentSetting) { + [self willChangeValueForKey:@"geolocationSettingIndex"]; + [self didChangeValueForKey:@"geolocationSettingIndex"]; + } +} + @end diff --git a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm index bec2abf3..2d6e90d 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm @@ -4,8 +4,12 @@ #import "chrome/browser/cocoa/content_settings_dialog_controller.h" +#import "base/scoped_nsobject.h" +#include "base/ref_counted.h" #include "chrome/browser/cocoa/browser_test_helper.h" #include "chrome/browser/cocoa/cocoa_test_helper.h" +#import "chrome/browser/geolocation/geolocation_content_settings_map.h" +#include "chrome/common/pref_names.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -13,19 +17,221 @@ namespace { class ContentSettingsDialogControllerTest : public CocoaTest { public: + virtual void SetUp() { + CocoaTest::SetUp(); + TestingProfile* profile = browser_helper_.profile(); + settingsMap_ = new HostContentSettingsMap(profile); + geoSettingsMap_ = new GeolocationContentSettingsMap(profile); + controller_ = [ContentSettingsDialogController + showContentSettingsForType:CONTENT_SETTINGS_TYPE_DEFAULT + profile:browser_helper_.profile()]; + } + + virtual void TearDown() { + [controller_ close]; + CocoaTest::TearDown(); + } + + protected: + ContentSettingsDialogController* controller_; BrowserTestHelper browser_helper_; + scoped_refptr<HostContentSettingsMap> settingsMap_; + scoped_refptr<GeolocationContentSettingsMap> geoSettingsMap_; }; // Test that +showContentSettingsDialogForProfile brings up the existing editor // and doesn't leak or crash. TEST_F(ContentSettingsDialogControllerTest, CreateDialog) { - Profile* profile(browser_helper_.profile()); - ContentSettingsDialogController* sharedInstance = - [ContentSettingsDialogController - showContentSettingsForType:CONTENT_SETTINGS_TYPE_DEFAULT - profile:profile]; - EXPECT_TRUE(sharedInstance); - [sharedInstance close]; + EXPECT_TRUE(controller_); +} + +TEST_F(ContentSettingsDialogControllerTest, CookieSetting) { + // Change setting, check dialog property. + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ cookieSettingIndex], kCookieEnabledIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_ASK); + EXPECT_EQ([controller_ cookieSettingIndex], kCookieAskIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, + CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ cookieSettingIndex], kCookieDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setCookieSettingIndex:kCookieEnabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setCookieSettingIndex:kCookieAskIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); + EXPECT_EQ(setting, CONTENT_SETTING_ASK); + + [controller_ setCookieSettingIndex:kCookieDisabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); +} + +TEST_F(ContentSettingsDialogControllerTest, BlockThirdPartyCookiesSetting) { + // Change setting, check dialog property. + settingsMap_->SetBlockThirdPartyCookies(YES); + EXPECT_TRUE([controller_ blockThirdPartyCookies]); + + settingsMap_->SetBlockThirdPartyCookies(NO); + EXPECT_FALSE([controller_ blockThirdPartyCookies]); + + // Change dialog property, check setting. + [controller_ setBlockThirdPartyCookies:YES]; + EXPECT_TRUE(settingsMap_->BlockThirdPartyCookies()); + + [controller_ setBlockThirdPartyCookies:NO]; + EXPECT_FALSE(settingsMap_->BlockThirdPartyCookies()); +} + +TEST_F(ContentSettingsDialogControllerTest, ClearSiteDataOnExitSetting) { + TestingProfile* profile = browser_helper_.profile(); + + // Change setting, check dialog property. + profile->GetPrefs()->SetBoolean(prefs::kClearSiteDataOnExit, true); + EXPECT_TRUE([controller_ clearSiteDataOnExit]); + + profile->GetPrefs()->SetBoolean(prefs::kClearSiteDataOnExit, false); + EXPECT_FALSE([controller_ clearSiteDataOnExit]); + + // Change dialog property, check setting. + [controller_ setClearSiteDataOnExit:YES]; + EXPECT_TRUE(profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit)); + + [controller_ setClearSiteDataOnExit:NO]; + EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit)); +} + +TEST_F(ContentSettingsDialogControllerTest, ImagesSetting) { + // Change setting, check dialog property. + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES, + CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ imagesEnabledIndex], kContentSettingsEnabledIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES, + CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ imagesEnabledIndex], kContentSettingsDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setImagesEnabledIndex:kContentSettingsEnabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setImagesEnabledIndex:kContentSettingsDisabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); +} + +TEST_F(ContentSettingsDialogControllerTest, JavaScriptSetting) { + // Change setting, check dialog property. + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, + CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ javaScriptEnabledIndex], kContentSettingsEnabledIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, + CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ javaScriptEnabledIndex], + kContentSettingsDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setJavaScriptEnabledIndex:kContentSettingsEnabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setJavaScriptEnabledIndex:kContentSettingsDisabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); +} + +TEST_F(ContentSettingsDialogControllerTest, PluginsSetting) { + // Change setting, check dialog property. + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, + CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ pluginsEnabledIndex], kContentSettingsEnabledIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, + CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ pluginsEnabledIndex], kContentSettingsDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setPluginsEnabledIndex:kContentSettingsEnabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setPluginsEnabledIndex:kContentSettingsDisabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); +} + +TEST_F(ContentSettingsDialogControllerTest, PopupsSetting) { + // Change setting, check dialog property. + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, + CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ popupsEnabledIndex], kContentSettingsEnabledIndex); + + settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, + CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ popupsEnabledIndex], kContentSettingsDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setPopupsEnabledIndex:kContentSettingsEnabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setPopupsEnabledIndex:kContentSettingsDisabledIndex]; + setting = + settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); +} + +TEST_F(ContentSettingsDialogControllerTest, GeolocationSetting) { + // Change setting, check dialog property. + geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_ALLOW); + EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationEnabledIndex); + + geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_ASK); + EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationAskIndex); + + geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); + EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationDisabledIndex); + + // Change dialog property, check setting. + NSInteger setting; + [controller_ setGeolocationSettingIndex:kGeolocationEnabledIndex]; + setting = + geoSettingsMap_->GetDefaultContentSetting(); + EXPECT_EQ(setting, CONTENT_SETTING_ALLOW); + + [controller_ setGeolocationSettingIndex:kGeolocationAskIndex]; + setting = + geoSettingsMap_->GetDefaultContentSetting(); + EXPECT_EQ(setting, CONTENT_SETTING_ASK); + + [controller_ setGeolocationSettingIndex:kGeolocationDisabledIndex]; + setting = + geoSettingsMap_->GetDefaultContentSetting(); + EXPECT_EQ(setting, CONTENT_SETTING_BLOCK); } } // namespace + |