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

Side by Side Diff: chrome/browser/cocoa/content_settings_dialog_controller_unittest.mm

Issue 2063020: Add observers to ContentSettingsDialogController so that the dialog will show... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/content_settings_dialog_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h"
6 6
7 #import "base/scoped_nsobject.h"
8 #include "base/ref_counted.h"
7 #include "chrome/browser/cocoa/browser_test_helper.h" 9 #include "chrome/browser/cocoa/browser_test_helper.h"
8 #include "chrome/browser/cocoa/cocoa_test_helper.h" 10 #include "chrome/browser/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/geolocation/geolocation_content_settings_map.h"
12 #include "chrome/common/pref_names.h"
9 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
11 15
12 namespace { 16 namespace {
13 17
14 class ContentSettingsDialogControllerTest : public CocoaTest { 18 class ContentSettingsDialogControllerTest : public CocoaTest {
15 public: 19 public:
20 virtual void SetUp() {
21 CocoaTest::SetUp();
22 TestingProfile* profile = browser_helper_.profile();
23 settingsMap_ = new HostContentSettingsMap(profile);
24 geoSettingsMap_ = new GeolocationContentSettingsMap(profile);
25 controller_ = [ContentSettingsDialogController
26 showContentSettingsForType:CONTENT_SETTINGS_TYPE_DEFAULT
27 profile:browser_helper_.profile()];
28 }
29
30 virtual void TearDown() {
31 [controller_ close];
32 CocoaTest::TearDown();
33 }
34
35 protected:
36 ContentSettingsDialogController* controller_;
16 BrowserTestHelper browser_helper_; 37 BrowserTestHelper browser_helper_;
38 scoped_refptr<HostContentSettingsMap> settingsMap_;
39 scoped_refptr<GeolocationContentSettingsMap> geoSettingsMap_;
17 }; 40 };
18 41
19 // Test that +showContentSettingsDialogForProfile brings up the existing editor 42 // Test that +showContentSettingsDialogForProfile brings up the existing editor
20 // and doesn't leak or crash. 43 // and doesn't leak or crash.
21 TEST_F(ContentSettingsDialogControllerTest, CreateDialog) { 44 TEST_F(ContentSettingsDialogControllerTest, CreateDialog) {
22 Profile* profile(browser_helper_.profile()); 45 EXPECT_TRUE(controller_);
23 ContentSettingsDialogController* sharedInstance = 46 }
24 [ContentSettingsDialogController 47
25 showContentSettingsForType:CONTENT_SETTINGS_TYPE_DEFAULT 48 TEST_F(ContentSettingsDialogControllerTest, CookieSetting) {
26 profile:profile]; 49 // Change setting, check dialog property.
27 EXPECT_TRUE(sharedInstance); 50 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
28 [sharedInstance close]; 51 CONTENT_SETTING_ALLOW);
52 EXPECT_EQ([controller_ cookieSettingIndex], kCookieEnabledIndex);
53
54 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
55 CONTENT_SETTING_ASK);
56 EXPECT_EQ([controller_ cookieSettingIndex], kCookieAskIndex);
57
58 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES,
59 CONTENT_SETTING_BLOCK);
60 EXPECT_EQ([controller_ cookieSettingIndex], kCookieDisabledIndex);
61
62 // Change dialog property, check setting.
63 NSInteger setting;
64 [controller_ setCookieSettingIndex:kCookieEnabledIndex];
65 setting =
66 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES);
67 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
68
69 [controller_ setCookieSettingIndex:kCookieAskIndex];
70 setting =
71 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES);
72 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
73
74 [controller_ setCookieSettingIndex:kCookieDisabledIndex];
75 setting =
76 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES);
77 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
78 }
79
80 TEST_F(ContentSettingsDialogControllerTest, BlockThirdPartyCookiesSetting) {
81 // Change setting, check dialog property.
82 settingsMap_->SetBlockThirdPartyCookies(YES);
83 EXPECT_TRUE([controller_ blockThirdPartyCookies]);
84
85 settingsMap_->SetBlockThirdPartyCookies(NO);
86 EXPECT_FALSE([controller_ blockThirdPartyCookies]);
87
88 // Change dialog property, check setting.
89 [controller_ setBlockThirdPartyCookies:YES];
90 EXPECT_TRUE(settingsMap_->BlockThirdPartyCookies());
91
92 [controller_ setBlockThirdPartyCookies:NO];
93 EXPECT_FALSE(settingsMap_->BlockThirdPartyCookies());
94 }
95
96 TEST_F(ContentSettingsDialogControllerTest, ClearSiteDataOnExitSetting) {
97 TestingProfile* profile = browser_helper_.profile();
98
99 // Change setting, check dialog property.
100 profile->GetPrefs()->SetBoolean(prefs::kClearSiteDataOnExit, true);
101 EXPECT_TRUE([controller_ clearSiteDataOnExit]);
102
103 profile->GetPrefs()->SetBoolean(prefs::kClearSiteDataOnExit, false);
104 EXPECT_FALSE([controller_ clearSiteDataOnExit]);
105
106 // Change dialog property, check setting.
107 [controller_ setClearSiteDataOnExit:YES];
108 EXPECT_TRUE(profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit));
109
110 [controller_ setClearSiteDataOnExit:NO];
111 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit));
112 }
113
114 TEST_F(ContentSettingsDialogControllerTest, ImagesSetting) {
115 // Change setting, check dialog property.
116 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES,
117 CONTENT_SETTING_ALLOW);
118 EXPECT_EQ([controller_ imagesEnabledIndex], kContentSettingsEnabledIndex);
119
120 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES,
121 CONTENT_SETTING_BLOCK);
122 EXPECT_EQ([controller_ imagesEnabledIndex], kContentSettingsDisabledIndex);
123
124 // Change dialog property, check setting.
125 NSInteger setting;
126 [controller_ setImagesEnabledIndex:kContentSettingsEnabledIndex];
127 setting =
128 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES);
129 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
130
131 [controller_ setImagesEnabledIndex:kContentSettingsDisabledIndex];
132 setting =
133 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES);
134 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
135 }
136
137 TEST_F(ContentSettingsDialogControllerTest, JavaScriptSetting) {
138 // Change setting, check dialog property.
139 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
140 CONTENT_SETTING_ALLOW);
141 EXPECT_EQ([controller_ javaScriptEnabledIndex], kContentSettingsEnabledIndex);
142
143 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
144 CONTENT_SETTING_BLOCK);
145 EXPECT_EQ([controller_ javaScriptEnabledIndex],
146 kContentSettingsDisabledIndex);
147
148 // Change dialog property, check setting.
149 NSInteger setting;
150 [controller_ setJavaScriptEnabledIndex:kContentSettingsEnabledIndex];
151 setting =
152 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
153 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
154
155 [controller_ setJavaScriptEnabledIndex:kContentSettingsDisabledIndex];
156 setting =
157 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
158 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
159 }
160
161 TEST_F(ContentSettingsDialogControllerTest, PluginsSetting) {
162 // Change setting, check dialog property.
163 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
164 CONTENT_SETTING_ALLOW);
165 EXPECT_EQ([controller_ pluginsEnabledIndex], kContentSettingsEnabledIndex);
166
167 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
168 CONTENT_SETTING_BLOCK);
169 EXPECT_EQ([controller_ pluginsEnabledIndex], kContentSettingsDisabledIndex);
170
171 // Change dialog property, check setting.
172 NSInteger setting;
173 [controller_ setPluginsEnabledIndex:kContentSettingsEnabledIndex];
174 setting =
175 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
176 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
177
178 [controller_ setPluginsEnabledIndex:kContentSettingsDisabledIndex];
179 setting =
180 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
181 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
182 }
183
184 TEST_F(ContentSettingsDialogControllerTest, PopupsSetting) {
185 // Change setting, check dialog property.
186 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS,
187 CONTENT_SETTING_ALLOW);
188 EXPECT_EQ([controller_ popupsEnabledIndex], kContentSettingsEnabledIndex);
189
190 settingsMap_->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS,
191 CONTENT_SETTING_BLOCK);
192 EXPECT_EQ([controller_ popupsEnabledIndex], kContentSettingsDisabledIndex);
193
194 // Change dialog property, check setting.
195 NSInteger setting;
196 [controller_ setPopupsEnabledIndex:kContentSettingsEnabledIndex];
197 setting =
198 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS);
199 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
200
201 [controller_ setPopupsEnabledIndex:kContentSettingsDisabledIndex];
202 setting =
203 settingsMap_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS);
204 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
205 }
206
207 TEST_F(ContentSettingsDialogControllerTest, GeolocationSetting) {
208 // Change setting, check dialog property.
209 geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_ALLOW);
210 EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationEnabledIndex);
211
212 geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_ASK);
213 EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationAskIndex);
214
215 geoSettingsMap_->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
216 EXPECT_EQ([controller_ geolocationSettingIndex], kGeolocationDisabledIndex);
217
218 // Change dialog property, check setting.
219 NSInteger setting;
220 [controller_ setGeolocationSettingIndex:kGeolocationEnabledIndex];
221 setting =
222 geoSettingsMap_->GetDefaultContentSetting();
223 EXPECT_EQ(setting, CONTENT_SETTING_ALLOW);
224
225 [controller_ setGeolocationSettingIndex:kGeolocationAskIndex];
226 setting =
227 geoSettingsMap_->GetDefaultContentSetting();
228 EXPECT_EQ(setting, CONTENT_SETTING_ASK);
229
230 [controller_ setGeolocationSettingIndex:kGeolocationDisabledIndex];
231 setting =
232 geoSettingsMap_->GetDefaultContentSetting();
233 EXPECT_EQ(setting, CONTENT_SETTING_BLOCK);
29 } 234 }
30 235
31 } // namespace 236 } // namespace
237
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/content_settings_dialog_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698