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

Side by Side Diff: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm

Issue 2743423004: Permissions: Show the reason for permission decisions made on the user's behalf. (Closed)
Patch Set: Review comments. Created 3 years, 8 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
OLDNEW
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/page_info_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/page_info/page_info_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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 namespace { 53 namespace {
54 54
55 // Indices of the menu items in the permission menu. 55 // Indices of the menu items in the permission menu.
56 enum PermissionMenuIndices { 56 enum PermissionMenuIndices {
57 kMenuIndexContentSettingAllow = 0, 57 kMenuIndexContentSettingAllow = 0,
58 kMenuIndexContentSettingBlock, 58 kMenuIndexContentSettingBlock,
59 kMenuIndexContentSettingDefault 59 kMenuIndexContentSettingDefault
60 }; 60 };
61 61
62 const ContentSettingsType kTestPermissionTypes[] = { 62 const ContentSettingsType kTestPermissionTypes[] = {
63 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_JAVASCRIPT, 63 CONTENT_SETTINGS_TYPE_IMAGES,
64 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_POPUPS, 64 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
65 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 65 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
66 CONTENT_SETTINGS_TYPE_PLUGINS,
67 CONTENT_SETTINGS_TYPE_POPUPS,
68 CONTENT_SETTINGS_TYPE_GEOLOCATION,
69 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
66 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}; 70 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC};
67 71
68 const ContentSetting kTestSettings[] = { 72 const ContentSetting kTestSettings[] = {
69 CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_ALLOW, 73 CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT,
70 CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, 74 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW,
71 CONTENT_SETTING_BLOCK}; 75 CONTENT_SETTING_BLOCK, CONTENT_SETTING_BLOCK};
72 76
73 const ContentSetting kTestDefaultSettings[] = {CONTENT_SETTING_BLOCK, 77 const ContentSetting kTestDefaultSettings[] = {
74 CONTENT_SETTING_ASK}; 78 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ASK};
75 79
76 const content_settings::SettingSource kTestSettingSources[] = { 80 const content_settings::SettingSource kTestSettingSources[] = {
77 content_settings::SETTING_SOURCE_USER, 81 content_settings::SETTING_SOURCE_USER,
78 content_settings::SETTING_SOURCE_USER, 82 content_settings::SETTING_SOURCE_USER,
79 content_settings::SETTING_SOURCE_USER, 83 content_settings::SETTING_SOURCE_USER,
80 content_settings::SETTING_SOURCE_USER, 84 content_settings::SETTING_SOURCE_USER,
85 content_settings::SETTING_SOURCE_USER,
81 content_settings::SETTING_SOURCE_POLICY, 86 content_settings::SETTING_SOURCE_POLICY,
82 content_settings::SETTING_SOURCE_POLICY, 87 content_settings::SETTING_SOURCE_POLICY,
83 content_settings::SETTING_SOURCE_EXTENSION}; 88 content_settings::SETTING_SOURCE_EXTENSION};
84 89
85 class PageInfoBubbleControllerTest : public CocoaTest { 90 class PageInfoBubbleControllerTest : public CocoaTest {
86 public: 91 public:
87 PageInfoBubbleControllerTest() { controller_ = nil; } 92 PageInfoBubbleControllerTest() { controller_ = nil; }
88 93
89 void TearDown() override { 94 void TearDown() override {
90 [controller_ close]; 95 [controller_ close];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 [views addObject:view]; 157 [views addObject:view];
153 } 158 }
154 return views; 159 return views;
155 } 160 }
156 161
157 // Sets up the dialog with some test permission settings. 162 // Sets up the dialog with some test permission settings.
158 void SetTestPermissions() { 163 void SetTestPermissions() {
159 // Create a list of 5 different permissions, corresponding to all the 164 // Create a list of 5 different permissions, corresponding to all the
160 // possible settings: 165 // possible settings:
161 // - [allow, block, ask] by default 166 // - [allow, block, ask] by default
162 // - [block, allow] * [by user, by policy, by extension] 167 // - [block, allow] * by user
163 PermissionInfoList permission_info_list; 168 PermissionInfoList permission_info_list;
164 PageInfoUI::PermissionInfo info; 169 PageInfoUI::PermissionInfo info;
165 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { 170 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) {
166 info.type = kTestPermissionTypes[i]; 171 info.type = kTestPermissionTypes[i];
167 info.setting = kTestSettings[i]; 172 info.setting = kTestSettings[i];
168 if (info.setting == CONTENT_SETTING_DEFAULT) 173 if (info.setting == CONTENT_SETTING_DEFAULT)
169 info.default_setting = kTestDefaultSettings[i]; 174 info.default_setting = kTestDefaultSettings[i];
170 info.source = kTestSettingSources[i]; 175 info.source = kTestSettingSources[i];
171 info.is_incognito = false; 176 info.is_incognito = false;
172 permission_info_list.push_back(info); 177 permission_info_list.push_back(info);
173 } 178 }
174 ChosenObjectInfoList chosen_object_info_list; 179 ChosenObjectInfoList chosen_object_info_list;
175 bridge_->SetPermissionInfo(permission_info_list, 180 bridge_->SetPermissionInfo(permission_info_list,
176 std::move(chosen_object_info_list)); 181 std::move(chosen_object_info_list));
177 } 182 }
178 183
184 int NumSettingsNotSetByUser() const {
185 int num_non_user_settings = 0;
186 for (size_t i = 0; i < arraysize(kTestSettingSources); ++i) {
187 num_non_user_settings +=
188 (kTestSettingSources[i] != content_settings::SETTING_SOURCE_USER) ? 1
189 : 0;
190 }
191 return num_non_user_settings;
192 }
193
179 content::TestBrowserThreadBundle thread_bundle_; 194 content::TestBrowserThreadBundle thread_bundle_;
180 TestingProfile profile_; 195 TestingProfile profile_;
181 content::TestWebContentsFactory web_contents_factory_; 196 content::TestWebContentsFactory web_contents_factory_;
182 197
183 PageInfoBubbleControllerForTesting* controller_; // Weak, owns self. 198 PageInfoBubbleControllerForTesting* controller_; // Weak, owns self.
184 NSWindow* window_; // Weak, owned by controller. 199 NSWindow* window_; // Weak, owned by controller.
185 }; 200 };
186 201
187 TEST_F(PageInfoBubbleControllerTest, ConnectionHelpButton) { 202 TEST_F(PageInfoBubbleControllerTest, ConnectionHelpButton) {
188 PageInfoUI::IdentityInfo info; 203 PageInfoUI::IdentityInfo info;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // when we set an identity with `show_ssl_decision_revoke_button == false` 241 // when we set an identity with `show_ssl_decision_revoke_button == false`
227 // again. 242 // again.
228 } 243 }
229 244
230 TEST_F(PageInfoBubbleControllerTest, SetPermissionInfo) { 245 TEST_F(PageInfoBubbleControllerTest, SetPermissionInfo) {
231 CreateBubble(); 246 CreateBubble();
232 SetTestPermissions(); 247 SetTestPermissions();
233 248
234 // There should be three subviews per permission. 249 // There should be three subviews per permission.
235 NSArray* subviews = [[controller_ permissionsView] subviews]; 250 NSArray* subviews = [[controller_ permissionsView] subviews];
236 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, [subviews count]); 251 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3,
252 [subviews count] - NumSettingsNotSetByUser());
237 253
238 // Ensure that there is a distinct label for each permission. 254 // Ensure that there is a label for each permission.
239 NSMutableSet* labels = [NSMutableSet set]; 255 NSMutableArray* permission_labels = [NSMutableArray array];
240 for (NSView* view in subviews) { 256 for (NSView* view in subviews) {
241 if ([view isKindOfClass:[NSTextField class]]) 257 if ([view isKindOfClass:[NSTextField class]])
242 [labels addObject:[static_cast<NSTextField*>(view) stringValue]]; 258 [permission_labels
259 addObject:[static_cast<NSTextField*>(view) stringValue]];
243 } 260 }
244 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); 261 EXPECT_EQ(arraysize(kTestPermissionTypes),
262 [permission_labels count] - NumSettingsNotSetByUser());
245 263
246 // Ensure that the button labels are distinct, and look for the correct 264 // Ensure that the button labels are distinct, and look for the correct
247 // number of disabled buttons. 265 // number of disabled buttons.
248 int disabled_count = 0; 266 int disabled_count = 0;
249 [labels removeAllObjects]; 267 NSMutableSet* button_labels = [NSMutableSet set];
250 for (NSView* view in subviews) { 268 for (NSView* view in subviews) {
251 if ([view isKindOfClass:[NSPopUpButton class]]) { 269 if ([view isKindOfClass:[NSPopUpButton class]]) {
252 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); 270 NSPopUpButton* button = static_cast<NSPopUpButton*>(view);
253 [labels addObject:[[button selectedCell] title]]; 271 [button_labels addObject:[[button selectedCell] title]];
254 272
255 if (![button isEnabled]) 273 if (![button isEnabled])
256 ++disabled_count; 274 ++disabled_count;
257 } 275 }
258 } 276 }
259 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); 277 EXPECT_EQ(5UL, [button_labels count]);
260 278
261 // 3 of the buttons should be disabled -- the ones that have a setting source 279 // Permissions with a setting source of SETTING_SOURCE_POLICY or
262 // of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION. 280 // SETTING_SOURCE_EXTENSION should have their buttons disabled.
263 EXPECT_EQ(3, disabled_count); 281 EXPECT_EQ(NumSettingsNotSetByUser(), disabled_count);
264 } 282 }
265 283
266 TEST_F(PageInfoBubbleControllerTest, WindowWidth) { 284 TEST_F(PageInfoBubbleControllerTest, WindowWidth) {
267 const CGFloat kBigEnoughBubbleWidth = 310; 285 const CGFloat kBigEnoughBubbleWidth = 310;
268 // Creating a window that should fit everything. 286 // Creating a window that should fit everything.
269 CreateBubbleWithWidth(kBigEnoughBubbleWidth); 287 CreateBubbleWithWidth(kBigEnoughBubbleWidth);
270 SetTestPermissions(); 288 SetTestPermissions();
271 289
272 CGFloat window_width = NSWidth([[controller_ window] frame]); 290 CGFloat window_width = NSWidth([[controller_ window] frame]);
273 291
(...skipping 20 matching lines...) Expand all
294 } 312 }
295 if ([view isKindOfClass:[NSPopUpButton class]]) { 313 if ([view isKindOfClass:[NSPopUpButton class]]) {
296 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); 314 NSPopUpButton* button = static_cast<NSPopUpButton*>(view);
297 EXPECT_LT(NSMaxX([button frame]), window_width); 315 EXPECT_LT(NSMaxX([button frame]), window_width);
298 } 316 }
299 } 317 }
300 } 318 }
301 } 319 }
302 320
303 } // namespace 321 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.mm ('k') | chrome/browser/ui/page_info/page_info_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698