OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/cocoa/page_info/website_settings_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info/website_settings_bubble_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 namespace { | 56 namespace { |
57 | 57 |
58 // Indices of the menu items in the permission menu. | 58 // Indices of the menu items in the permission menu. |
59 enum PermissionMenuIndices { | 59 enum PermissionMenuIndices { |
60 kMenuIndexContentSettingAllow = 0, | 60 kMenuIndexContentSettingAllow = 0, |
61 kMenuIndexContentSettingBlock, | 61 kMenuIndexContentSettingBlock, |
62 kMenuIndexContentSettingDefault | 62 kMenuIndexContentSettingDefault |
63 }; | 63 }; |
64 | 64 |
65 const ContentSettingsType kTestPermissionTypes[] = { | 65 const ContentSettingsType kTestPermissionTypes[] = { |
66 CONTENT_SETTINGS_TYPE_IMAGES, | 66 CONTENT_SETTINGS_TYPE_IMAGES, |
67 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 67 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
68 CONTENT_SETTINGS_TYPE_PLUGINS, | 68 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
69 CONTENT_SETTINGS_TYPE_POPUPS, | 69 CONTENT_SETTINGS_TYPE_PLUGINS, |
70 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 70 CONTENT_SETTINGS_TYPE_POPUPS, |
71 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 71 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
72 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | 72 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
73 }; | 73 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}; |
74 | 74 |
75 const ContentSetting kTestSettings[] = { | 75 const ContentSetting kTestSettings[] = { |
76 CONTENT_SETTING_DEFAULT, | 76 CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, |
77 CONTENT_SETTING_DEFAULT, | 77 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW, |
78 CONTENT_SETTING_ALLOW, | 78 CONTENT_SETTING_BLOCK, CONTENT_SETTING_BLOCK}; |
79 CONTENT_SETTING_BLOCK, | |
80 CONTENT_SETTING_ALLOW, | |
81 CONTENT_SETTING_BLOCK, | |
82 CONTENT_SETTING_BLOCK | |
83 }; | |
84 | 79 |
85 const ContentSetting kTestDefaultSettings[] = { | 80 const ContentSetting kTestDefaultSettings[] = { |
86 CONTENT_SETTING_BLOCK, | 81 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ASK}; |
87 CONTENT_SETTING_ASK | |
88 }; | |
89 | 82 |
90 const content_settings::SettingSource kTestSettingSources[] = { | 83 const content_settings::SettingSource kTestSettingSources[] = { |
91 content_settings::SETTING_SOURCE_USER, | 84 content_settings::SETTING_SOURCE_USER, |
92 content_settings::SETTING_SOURCE_USER, | 85 content_settings::SETTING_SOURCE_USER, |
93 content_settings::SETTING_SOURCE_USER, | 86 content_settings::SETTING_SOURCE_USER, |
94 content_settings::SETTING_SOURCE_USER, | 87 content_settings::SETTING_SOURCE_USER, |
95 content_settings::SETTING_SOURCE_POLICY, | 88 content_settings::SETTING_SOURCE_USER, |
96 content_settings::SETTING_SOURCE_POLICY, | 89 content_settings::SETTING_SOURCE_POLICY, |
97 content_settings::SETTING_SOURCE_EXTENSION | 90 content_settings::SETTING_SOURCE_POLICY, |
98 }; | 91 content_settings::SETTING_SOURCE_EXTENSION}; |
99 | 92 |
100 class WebsiteSettingsBubbleControllerTest : public CocoaTest { | 93 class WebsiteSettingsBubbleControllerTest : public CocoaTest { |
101 public: | 94 public: |
102 WebsiteSettingsBubbleControllerTest() { | 95 WebsiteSettingsBubbleControllerTest() { |
103 controller_ = nil; | 96 controller_ = nil; |
104 } | 97 } |
105 | 98 |
106 void TearDown() override { | 99 void TearDown() override { |
107 [controller_ close]; | 100 [controller_ close]; |
108 CocoaTest::TearDown(); | 101 CocoaTest::TearDown(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 [views addObject:view]; | 167 [views addObject:view]; |
175 } | 168 } |
176 return views; | 169 return views; |
177 } | 170 } |
178 | 171 |
179 // Sets up the dialog with some test permission settings. | 172 // Sets up the dialog with some test permission settings. |
180 void SetTestPermissions() { | 173 void SetTestPermissions() { |
181 // Create a list of 5 different permissions, corresponding to all the | 174 // Create a list of 5 different permissions, corresponding to all the |
182 // possible settings: | 175 // possible settings: |
183 // - [allow, block, ask] by default | 176 // - [allow, block, ask] by default |
184 // - [block, allow] * [by user, by policy, by extension] | 177 // - [block, allow] by user |
185 PermissionInfoList permission_info_list; | 178 PermissionInfoList permission_info_list; |
186 WebsiteSettingsUI::PermissionInfo info; | 179 WebsiteSettingsUI::PermissionInfo info; |
187 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { | 180 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { |
188 info.type = kTestPermissionTypes[i]; | 181 info.type = kTestPermissionTypes[i]; |
189 info.setting = kTestSettings[i]; | 182 info.setting = kTestSettings[i]; |
190 if (info.setting == CONTENT_SETTING_DEFAULT) | 183 if (info.setting == CONTENT_SETTING_DEFAULT) |
191 info.default_setting = kTestDefaultSettings[i]; | 184 info.default_setting = kTestDefaultSettings[i]; |
192 info.source = kTestSettingSources[i]; | 185 info.source = kTestSettingSources[i]; |
193 info.is_incognito = false; | 186 info.is_incognito = false; |
194 permission_info_list.push_back(info); | 187 permission_info_list.push_back(info); |
195 } | 188 } |
196 ChosenObjectInfoList chosen_object_info_list; | 189 ChosenObjectInfoList chosen_object_info_list; |
197 bridge_->SetPermissionInfo(permission_info_list, | 190 bridge_->SetPermissionInfo(permission_info_list, |
198 std::move(chosen_object_info_list)); | 191 std::move(chosen_object_info_list)); |
199 } | 192 } |
200 | 193 |
194 int NumSettingsNotSetByUser() const { | |
195 int num_non_user_settings = 0; | |
196 for (size_t i = 0; i < arraysize(kTestSettingSources); ++i) { | |
197 num_non_user_settings += | |
198 (kTestSettingSources[i] != content_settings::SETTING_SOURCE_USER) ? 1 | |
199 : 0; | |
200 } | |
201 return num_non_user_settings; | |
202 } | |
203 | |
201 content::TestBrowserThreadBundle thread_bundle_; | 204 content::TestBrowserThreadBundle thread_bundle_; |
202 TestingProfile profile_; | 205 TestingProfile profile_; |
203 content::TestWebContentsFactory web_contents_factory_; | 206 content::TestWebContentsFactory web_contents_factory_; |
204 | 207 |
205 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. | 208 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. |
206 NSWindow* window_; // Weak, owned by controller. | 209 NSWindow* window_; // Weak, owned by controller. |
207 }; | 210 }; |
208 | 211 |
209 TEST_F(WebsiteSettingsBubbleControllerTest, ConnectionHelpButton) { | 212 TEST_F(WebsiteSettingsBubbleControllerTest, ConnectionHelpButton) { |
210 WebsiteSettingsUI::IdentityInfo info; | 213 WebsiteSettingsUI::IdentityInfo info; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // when we set an identity with `show_ssl_decision_revoke_button == false` | 250 // when we set an identity with `show_ssl_decision_revoke_button == false` |
248 // again. | 251 // again. |
249 } | 252 } |
250 | 253 |
251 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { | 254 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { |
252 CreateBubble(); | 255 CreateBubble(); |
253 SetTestPermissions(); | 256 SetTestPermissions(); |
254 | 257 |
255 // There should be three subviews per permission. | 258 // There should be three subviews per permission. |
256 NSArray* subviews = [[controller_ permissionsView] subviews]; | 259 NSArray* subviews = [[controller_ permissionsView] subviews]; |
257 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3 , [subviews count]); | 260 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, |
261 [subviews count] - NumSettingsNotSetByUser()); | |
258 | 262 |
259 // Ensure that there is a distinct label for each permission. | 263 // Ensure that there is a label for each permission. |
260 NSMutableSet* labels = [NSMutableSet set]; | 264 NSMutableArray* permission_labels = [NSMutableArray array]; |
261 for (NSView* view in subviews) { | 265 for (NSView* view in subviews) { |
262 if ([view isKindOfClass:[NSTextField class]]) | 266 if ([view isKindOfClass:[NSTextField class]]) |
263 [labels addObject:[static_cast<NSTextField*>(view) stringValue]]; | 267 [permission_labels |
268 addObject:[static_cast<NSTextField*>(view) stringValue]]; | |
264 } | 269 } |
265 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); | 270 EXPECT_EQ(arraysize(kTestPermissionTypes), |
271 [permission_labels count] - NumSettingsNotSetByUser()); | |
266 | 272 |
267 // Ensure that the button labels are distinct, and look for the correct | 273 // Ensure that the button labels are distinct, and look for the correct |
268 // number of disabled buttons. | 274 // number of disabled buttons. |
269 int disabled_count = 0; | 275 int disabled_count = 0; |
270 [labels removeAllObjects]; | 276 NSMutableSet* button_labels = [NSMutableSet set]; |
271 for (NSView* view in subviews) { | 277 for (NSView* view in subviews) { |
272 if ([view isKindOfClass:[NSPopUpButton class]]) { | 278 if ([view isKindOfClass:[NSPopUpButton class]]) { |
273 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); | 279 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); |
274 [labels addObject:[[button selectedCell] title]]; | 280 [button_labels addObject:[[button selectedCell] title]]; |
275 | 281 |
276 if (![button isEnabled]) | 282 if (![button isEnabled]) |
277 ++disabled_count; | 283 ++disabled_count; |
278 } | 284 } |
279 } | 285 } |
280 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); | 286 EXPECT_EQ(5UL, [button_labels count]); |
281 | 287 |
282 // 3 of the buttons should be disabled -- the ones that have a setting source | 288 // All non-user set settings should have disabled buttons (i.e., the ones with |
283 // of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION. | 289 // a setting source of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION). |
284 EXPECT_EQ(3, disabled_count); | 290 EXPECT_EQ(NumSettingsNotSetByUser(), disabled_count); |
285 } | 291 } |
286 | 292 |
dominickn
2017/03/26 23:46:24
Should you add a test for the embargoed permission
Patti Lor
2017/03/27 05:52:40
I think it's possible, but since we can't tell if
| |
287 TEST_F(WebsiteSettingsBubbleControllerTest, WindowWidth) { | 293 TEST_F(WebsiteSettingsBubbleControllerTest, WindowWidth) { |
288 const CGFloat kBigEnoughBubbleWidth = 310; | 294 const CGFloat kBigEnoughBubbleWidth = 310; |
289 // Creating a window that should fit everything. | 295 // Creating a window that should fit everything. |
290 CreateBubbleWithWidth(kBigEnoughBubbleWidth); | 296 CreateBubbleWithWidth(kBigEnoughBubbleWidth); |
291 SetTestPermissions(); | 297 SetTestPermissions(); |
292 | 298 |
293 CGFloat window_width = NSWidth([[controller_ window] frame]); | 299 CGFloat window_width = NSWidth([[controller_ window] frame]); |
294 | 300 |
295 // Check the window was made bigger to fit the content. | 301 // Check the window was made bigger to fit the content. |
296 EXPECT_EQ(kBigEnoughBubbleWidth, window_width); | 302 EXPECT_EQ(kBigEnoughBubbleWidth, window_width); |
(...skipping 18 matching lines...) Expand all Loading... | |
315 } | 321 } |
316 if ([view isKindOfClass:[NSPopUpButton class]]) { | 322 if ([view isKindOfClass:[NSPopUpButton class]]) { |
317 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); | 323 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); |
318 EXPECT_LT(NSMaxX([button frame]), window_width); | 324 EXPECT_LT(NSMaxX([button frame]), window_width); |
319 } | 325 } |
320 } | 326 } |
321 } | 327 } |
322 } | 328 } |
323 | 329 |
324 } // namespace | 330 } // namespace |
OLD | NEW |